Really shoulda started version control a while ago....

This commit is contained in:
petra-fied 2021-12-30 01:38:52 +10:00
commit d20f1aa01d
10 changed files with 2495 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Poetry (TextureSynthesis-StyleSwap) (2)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
</modules>
</component>
</project>

6
.idea/other.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>

10
.idea/pythonProject.iml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Poetry (TextureSynthesis-StyleSwap) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

49
main.py Normal file
View file

@ -0,0 +1,49 @@
import os
from pathlib import Path
from typing import Optional
import tensorflow_hub as hub
import tensorflow as tf
from keras import backend as be
from matplotlib import pyplot as plt
import numpy as np
import cv2
model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
def load_image(img_path: str) -> (Optional[Path], Optional[object]):
if os.path.isfile(img_path):
img = tf.io.read_file(img_path)
img = tf.image.decode_image(img, channels=3)
img = tf.image.convert_image_dtype(img, tf.float32)
img = img[tf.newaxis, :]
return Path(img_path), img
else:
print(f"Couldn't find {img_path}!")
return None, None
while True:
content_image = None
content_path: Optional[Path] = None
# while content_image is None:
# content_path, content_image = load_image(f'inputs/{input("Content image: ")}')
# style_image, style_path = None, None
# while style_image is None:
# style_path, style_image = load_image(f'styles/{input("Style image: ")}')
style_path, style_image = load_image(f'styles/{input("Style image: ")}')
print("Processing...")
for file in os.listdir("inputs"):
content_path, content_image = load_image(f'inputs/{file}')
stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]
out = "outputs/" + style_path.stem + "_" + content_path.stem + ".jpg"
cv2.imwrite(out, cv2.cvtColor(np.squeeze(stylized_image) * 255, cv2.COLOR_BGR2RGB))
print(f"Done! Wrote file to {out}.")
be.clear_session()
tf.keras.backend.clear_session()
# stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]
# out = "outputs/" + os.path.splitext(content_path.name)[0] + "_" + os.path.splitext(style_path.name)[0] + ".jpg"
# cv2.imwrite(out, cv2.cvtColor(np.squeeze(stylized_image) * 255, cv2.COLOR_BGR2RGB))
# print(f"Done! Wrote file to {out}.")

2377
poetry.lock generated Normal file

File diff suppressed because it is too large Load diff

21
pyproject.toml Normal file
View file

@ -0,0 +1,21 @@
[tool.poetry]
name = "texturesynthesis-styleswap"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "~3.9"
numpy = "^1.21.4"
tensorflow = "^2.7.0"
tensorflow-hub = "^0.12.0"
matplotlib = "^3.5.1"
opencv-python = "^4.5.4"
ipython = "^7.30.1"
jupyter = "^1.0.0"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"