Franco Astegiano commited on
Commit
db9e08e
1 Parent(s): 67eb3ce

Update tf_hub_fast_style_transfer_for_arbitrary_styles.py

Browse files
examples/colab/tf_hub_fast_style_transfer_for_arbitrary_styles.py CHANGED
@@ -107,12 +107,15 @@ def show_n(images, titles=('',)):
107
  plt.title(titles[i] if len(titles) > i else '')
108
  plt.show()
109
 
 
 
 
110
  """Let's get as well some images to play with."""
111
 
112
  # @title Load example images { display-mode: "form" }
113
 
114
- content_image_url = 'https://live.staticflickr.com/65535/52032998695_f57c61746c_c.jpg' # @param {type:"string"}
115
- style_image_url = 'https://live.staticflickr.com/65535/52032731604_a815a0b19f_c.jpg' # @param {type:"string"}
116
  output_image_size = 384 # @param {type:"integer"}
117
 
118
  # The content image size can be arbitrary.
@@ -122,8 +125,16 @@ content_img_size = (output_image_size, output_image_size)
122
  # well but will lead to different results).
123
  style_img_size = (256, 256) # Recommended to keep it at 256.
124
 
125
- content_image = load_image(content_image_url, content_img_size)
126
- style_image = load_image(style_image_url, style_img_size)
 
 
 
 
 
 
 
 
127
  style_image = tf.nn.avg_pool(style_image, ksize=[3,3], strides=[1,1], padding='SAME')
128
  show_n([content_image, style_image], ['Content image', 'Style image'])
129
 
@@ -155,6 +166,10 @@ is the same as the content image shape.
155
  # This is pretty fast within a few milliseconds on a GPU.
156
 
157
  def modify(imageinput,style_input):
 
 
 
 
158
  outputs = hub_module(tf.constant(imageinput), tf.constant(style_input))
159
  return outputs[0]
160
  #stylized_image = outputs[0]
@@ -165,8 +180,6 @@ def modify(imageinput,style_input):
165
 
166
  # Gradio app
167
 
168
- content_image_input = gr.inputs.Image(label="Content Image")
169
- style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")
170
 
171
  app_interface = gr.Interface(modify,
172
  inputs=[content_image_input, style_image_input],
 
107
  plt.title(titles[i] if len(titles) > i else '')
108
  plt.show()
109
 
110
+
111
+
112
+
113
  """Let's get as well some images to play with."""
114
 
115
  # @title Load example images { display-mode: "form" }
116
 
117
+ #content_image_url = 'https://live.staticflickr.com/65535/52032998695_f57c61746c_c.jpg' # @param {type:"string"}
118
+ #style_image_url = 'https://live.staticflickr.com/65535/52032731604_a815a0b19f_c.jpg' # @param {type:"string"}
119
  output_image_size = 384 # @param {type:"integer"}
120
 
121
  # The content image size can be arbitrary.
 
125
  # well but will lead to different results).
126
  style_img_size = (256, 256) # Recommended to keep it at 256.
127
 
128
+
129
+
130
+ # Load images from app
131
+ content_image_input = gr.inputs.Image(label="Content Image")
132
+ style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")
133
+
134
+
135
+
136
+ content_image = load_image(content_image_input, content_img_size)
137
+ style_image = load_image(style_image_input, style_img_size)
138
  style_image = tf.nn.avg_pool(style_image, ksize=[3,3], strides=[1,1], padding='SAME')
139
  show_n([content_image, style_image], ['Content image', 'Style image'])
140
 
 
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]
175
  #stylized_image = outputs[0]
 
180
 
181
  # Gradio app
182
 
 
 
183
 
184
  app_interface = gr.Interface(modify,
185
  inputs=[content_image_input, style_image_input],