Spaces:
Running
Running
Franco Astegiano
commited on
Commit
•
fb1dd41
1
Parent(s):
9fa990b
Update app.py
Browse files
app.py
CHANGED
@@ -82,15 +82,15 @@ def crop_center(image):
|
|
82 |
return image
|
83 |
|
84 |
@functools.lru_cache(maxsize=None)
|
85 |
-
def load_image(
|
86 |
"""Loads and preprocesses images."""
|
87 |
# Cache image file locally.
|
88 |
-
image_path = tf.keras.utils.get_file(os.path.basename(image_url)[-128:], image_url)
|
89 |
# Load and convert to float32 numpy array, add batch dimension, and normalize to range [0, 1].
|
90 |
-
img = tf.io.decode_image(
|
91 |
tf.io.read_file(image_path),
|
92 |
channels=3, dtype=tf.float32)[tf.newaxis, ...]
|
93 |
-
img = crop_center(
|
94 |
img = tf.image.resize(img, image_size, preserve_aspect_ratio=True)
|
95 |
return img
|
96 |
|
@@ -166,9 +166,9 @@ is the same as the content image shape.
|
|
166 |
# This is pretty fast within a few milliseconds on a GPU.
|
167 |
|
168 |
def modify(imageinput,style_input):
|
169 |
-
|
170 |
-
|
171 |
-
style_image = tf.nn.avg_pool(
|
172 |
#show_n([content_image, style_image], ['Content image', 'Style image'])
|
173 |
outputs = hub_module(tf.constant(imageinput), tf.constant(style_input))
|
174 |
return outputs[0]
|
|
|
82 |
return image
|
83 |
|
84 |
@functools.lru_cache(maxsize=None)
|
85 |
+
def load_image(image, image_size=(256, 256), preserve_aspect_ratio=True):
|
86 |
"""Loads and preprocesses images."""
|
87 |
# Cache image file locally.
|
88 |
+
#image_path = tf.keras.utils.get_file(os.path.basename(image_url)[-128:], image_url)
|
89 |
# Load and convert to float32 numpy array, add batch dimension, and normalize to range [0, 1].
|
90 |
+
#img = tf.io.decode_image(
|
91 |
tf.io.read_file(image_path),
|
92 |
channels=3, dtype=tf.float32)[tf.newaxis, ...]
|
93 |
+
img = crop_center(image)
|
94 |
img = tf.image.resize(img, image_size, preserve_aspect_ratio=True)
|
95 |
return img
|
96 |
|
|
|
166 |
# This is pretty fast within a few milliseconds on a GPU.
|
167 |
|
168 |
def modify(imageinput,style_input):
|
169 |
+
content_image = load_image(imageinput, content_img_size)
|
170 |
+
style_image = load_image(style_input, style_img_size)
|
171 |
+
style_image = tf.nn.avg_pool(style_image, ksize=[3,3], strides=[1,1], padding='SAME')
|
172 |
#show_n([content_image, style_image], ['Content image', 'Style image'])
|
173 |
outputs = hub_module(tf.constant(imageinput), tf.constant(style_input))
|
174 |
return outputs[0]
|