-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_style_transfer.py
More file actions
35 lines (25 loc) · 1.08 KB
/
fast_style_transfer.py
File metadata and controls
35 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import tensorflow as tf
import tensorflow_hub as hub
from setup import tensor_to_image
def fast_style_transfer(content_image, style_image):
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
return tensor_to_image(stylized_image)
def complete_fast_algorithm(content_path, style_path, img_size = 512):
"""
returns the instance of image which represents the result
"""
import matplotlib.pyplot as plt
from setup import load_img
from visualization import imshow
print('Loading Images ---')
content_image = load_img(content_path, img_size)
style_image = load_img(style_path, img_size)
print('Executing style transfer, this could take a moment\nPlease wait...')
result_image = fast_style_transfer(content_image, style_image)
print('plotting images -->')
plt.subplot(2, 2, 1)
imshow(content_image, 'Content image')
plt.subplot(2, 2, 2)
imshow(style_image, 'Style image')
return result_image