-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christoph Theiß
committed
May 8, 2021
1 parent
3db423b
commit a233c0f
Showing
14 changed files
with
392 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
backend/app/models/ | ||
|
||
# VS Code | ||
.vscode/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
import tensorflow as tf | ||
from PIL import Image | ||
|
||
def wrap_frozen_graph(graph_def, inputs, outputs, print_graph=False): | ||
def _imports_graph_def(): | ||
tf.compat.v1.import_graph_def(graph_def, name="") | ||
|
||
wrapped_import = tf.compat.v1.wrap_function(_imports_graph_def, []) | ||
import_graph = wrapped_import.graph | ||
|
||
layers = [op.name for op in import_graph.get_operations()] | ||
if print_graph == True: | ||
for layer in layers: | ||
print(layer) | ||
return wrapped_import.prune( | ||
tf.nest.map_structure(import_graph.as_graph_element, inputs), | ||
tf.nest.map_structure(import_graph.as_graph_element, outputs)) | ||
|
||
def load_artist_graph(artist, model_path): | ||
print(f"Loading model for {artist}.") | ||
try: | ||
with tf.io.gfile.GFile(model_path / artist / "frozen_model.pb", "rb") as f: | ||
graph_def = tf.compat.v1.GraphDef() | ||
loaded = graph_def.ParseFromString(f.read()) | ||
frozen_func = wrap_frozen_graph(graph_def, ["placeholder/photo:0"], ["decoder/sub:0"]) | ||
except FileNotFoundError: | ||
def frozen_func(x): | ||
return x | ||
return frozen_func | ||
|
||
def artify(image, model): | ||
image = image.convert("RGB") | ||
np_image = np.asarray(image) | ||
input_image = ( | ||
tf.expand_dims(tf.constant(np_image, dtype=tf.float32), 0) / 127.5 - 1.0 | ||
) | ||
artified = (model(input_image)[0] + 1) * 127.5 | ||
artified = Image.fromarray(tf.squeeze(artified, 0).numpy().astype(np.uint8)) | ||
return artified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
opencv-python~=4.5 | ||
numpy~=1.20 | ||
numpy~=1.19 | ||
tqdm~=4.60 | ||
Pillow~=8.2 | ||
flask~=1.1 | ||
flask-cors~=3.0 | ||
flask-restful~=0.3.8 | ||
flask-talisman~=0.7.0 | ||
flask-talisman~=0.7.0 | ||
tensorflow~=2.5 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.