diff options
-rw-r--r-- | __pycache__/hyperparameters.cpython-38.pyc | bin | 324 -> 344 bytes | |||
-rw-r--r-- | __pycache__/losses.cpython-38.pyc | bin | 4601 -> 4664 bytes | |||
-rw-r--r-- | content.jpg | bin | 0 -> 45172 bytes | |||
-rw-r--r-- | hyperparameters.py | 8 | ||||
-rw-r--r-- | losses.py | 10 | ||||
-rw-r--r-- | main.py | 4 | ||||
-rw-r--r-- | save.jpg | bin | 13084 -> 19949 bytes | |||
-rw-r--r-- | style.jpg | bin | 0 -> 43386 bytes |
8 files changed, 11 insertions, 11 deletions
diff --git a/__pycache__/hyperparameters.cpython-38.pyc b/__pycache__/hyperparameters.cpython-38.pyc Binary files differindex e42d48d1..12ab00e4 100644 --- a/__pycache__/hyperparameters.cpython-38.pyc +++ b/__pycache__/hyperparameters.cpython-38.pyc diff --git a/__pycache__/losses.cpython-38.pyc b/__pycache__/losses.cpython-38.pyc Binary files differindex 07bf7a33..d25c70d0 100644 --- a/__pycache__/losses.cpython-38.pyc +++ b/__pycache__/losses.cpython-38.pyc diff --git a/content.jpg b/content.jpg Binary files differnew file mode 100644 index 00000000..163629cd --- /dev/null +++ b/content.jpg diff --git a/hyperparameters.py b/hyperparameters.py index a15d04ac..75528742 100644 --- a/hyperparameters.py +++ b/hyperparameters.py @@ -9,17 +9,17 @@ Number of epochs. If you experiment with more complex networks you might need to increase this. Likewise if you add regularization that slows training. """ -num_epochs = 10000 +num_epochs = 500 """ A critical parameter that can dramatically affect whether training succeeds or fails. The value for this depends significantly on which optimizer is used. Refer to the default learning rate parameter """ -learning_rate = .002 +learning_rate = 1e2 momentum = 0.01 -alpha = 1e-2 +alpha = 1 -beta = 5e1 +beta = 100 @@ -11,16 +11,16 @@ class YourModel(tf.keras.Model): def __init__(self, content_image, style_image): #normalize these images to float values super(YourModel, self).__init__() - self.content_image = transform.resize(content_image, tf.shape(style_image), anti_aliasing=True) + self.content_image = transform.resize(content_image, tf.shape(style_image), anti_aliasing=True, preserve_range=True).astype('uint8') self.content_image = tf.expand_dims(self.content_image, axis=0) print(self.content_image) #perhaps consider cropping to avoid distortion - self.style_image = transform.resize(style_image, tf.shape(style_image), anti_aliasing=True) + self.style_image = transform.resize(style_image, tf.shape(style_image), anti_aliasing=True, preserve_range=True).astype('uint8') self.style_image = tf.expand_dims(self.style_image, axis=0) #self.x = tf.Variable(initial_value = self.content_image.numpy().astype(np.float32), trainable=True) self.x = tf.Variable(initial_value = np.random.rand(self.content_image.shape[0], - self.content_image.shape[1], self.content_image.shape[2], self.content_image.shape[3]).astype(np.float32), trainable=True) + self.content_image.shape[1], self.content_image.shape[2], self.content_image.shape[3]).astype('uint8'), trainable=True) self.alpha = hp.alpha self.beta = hp.beta @@ -117,7 +117,7 @@ class YourModel(tf.keras.Model): return (self.alpha * content_l) + (self.beta * style_l) def content_loss(self, photo_layers, input_layers): - L_content = tf.constant(0.0) + L_content = tf.constant(0.0).astype('uint8') for i in range(len(photo_layers)): pl = photo_layers[i] il = input_layers[i] @@ -166,7 +166,7 @@ class YourModel(tf.keras.Model): for i in range(len(art_layers)): art_layer = art_layers[i] input_layer = input_layers[i] - L_style = tf.math.add(L_style, self.layer_loss(art_layer, input_layer)*(1/5)) + L_style = tf.math.add(L_style, (1/5)*self.layer_loss(art_layer, input_layer)) #print('style loss', L_style) return L_style @@ -13,6 +13,7 @@ from losses import YourModel from skimage.io import imread, imsave from matplotlib import pyplot as plt import numpy as np +from skimage import transform def parse_args(): @@ -53,8 +54,7 @@ def main(): content_image = imread(ARGS.content) style_image = imread(ARGS.style) - style_image = transform.resize(style_image, content_image.shape, anti_aliasing=True) - + style_image = transform.resize(style_image, content_image.shape).astype('uint8') my_model = YourModel(content_image=content_image, style_image=style_image) my_model.vgg16.build([1, 255, 255, 3]) my_model.vgg16.load_weights('vgg16_imagenet.h5', by_name=True) Binary files differdiff --git a/style.jpg b/style.jpg Binary files differnew file mode 100644 index 00000000..105ac2d1 --- /dev/null +++ b/style.jpg |