diff options
-rw-r--r-- | __pycache__/hyperparameters.cpython-38.pyc | bin | 0 -> 348 bytes | |||
-rw-r--r-- | __pycache__/losses.cpython-38.pyc | bin | 0 -> 4661 bytes | |||
-rw-r--r-- | checkpoint-images/img-epoch0.jpg | bin | 0 -> 4723 bytes | |||
-rw-r--r-- | checkpoint-images/img-epoch100.jpg | bin | 0 -> 114642 bytes | |||
-rw-r--r-- | checkpoint-images/img-epoch200.jpg | bin | 0 -> 2227 bytes | |||
-rw-r--r-- | checkpoint-images/img-epoch300.jpg | bin | 0 -> 2227 bytes | |||
-rw-r--r-- | checkpoint-images/img-epoch400.jpg | bin | 0 -> 2227 bytes | |||
-rw-r--r-- | hyperparameters.py | 8 | ||||
-rw-r--r-- | losses.py | 17 | ||||
-rw-r--r-- | main.py | 4 | ||||
-rw-r--r-- | save.jpg | bin | 19949 -> 172131 bytes |
11 files changed, 19 insertions, 10 deletions
diff --git a/__pycache__/hyperparameters.cpython-38.pyc b/__pycache__/hyperparameters.cpython-38.pyc Binary files differnew file mode 100644 index 00000000..3162d698 --- /dev/null +++ b/__pycache__/hyperparameters.cpython-38.pyc diff --git a/__pycache__/losses.cpython-38.pyc b/__pycache__/losses.cpython-38.pyc Binary files differnew file mode 100644 index 00000000..7c0a4b73 --- /dev/null +++ b/__pycache__/losses.cpython-38.pyc diff --git a/checkpoint-images/img-epoch0.jpg b/checkpoint-images/img-epoch0.jpg Binary files differnew file mode 100644 index 00000000..4836b9e8 --- /dev/null +++ b/checkpoint-images/img-epoch0.jpg diff --git a/checkpoint-images/img-epoch100.jpg b/checkpoint-images/img-epoch100.jpg Binary files differnew file mode 100644 index 00000000..dfcf28e2 --- /dev/null +++ b/checkpoint-images/img-epoch100.jpg diff --git a/checkpoint-images/img-epoch200.jpg b/checkpoint-images/img-epoch200.jpg Binary files differnew file mode 100644 index 00000000..13fde882 --- /dev/null +++ b/checkpoint-images/img-epoch200.jpg diff --git a/checkpoint-images/img-epoch300.jpg b/checkpoint-images/img-epoch300.jpg Binary files differnew file mode 100644 index 00000000..13fde882 --- /dev/null +++ b/checkpoint-images/img-epoch300.jpg diff --git a/checkpoint-images/img-epoch400.jpg b/checkpoint-images/img-epoch400.jpg Binary files differnew file mode 100644 index 00000000..13fde882 --- /dev/null +++ b/checkpoint-images/img-epoch400.jpg diff --git a/hyperparameters.py b/hyperparameters.py index 75528742..ac2beda8 100644 --- a/hyperparameters.py +++ b/hyperparameters.py @@ -9,7 +9,7 @@ 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 = 500 +num_epochs = 200 """ A critical parameter that can dramatically affect whether training @@ -20,6 +20,8 @@ learning_rate = 1e2 momentum = 0.01 -alpha = 1 +alpha = .05 +beta = 5 +# alpha = 1e-5 -beta = 100 +# beta = 1e-2 @@ -11,16 +11,19 @@ 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, clip=False) self.content_image = tf.expand_dims(self.content_image, axis=0) + # self.content_image = self.content_image.astype('uint8') 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, clip=False) self.style_image = tf.expand_dims(self.style_image, axis=0) + # self.style_image = self.style_image.astype('uint8') #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(np.float32), trainable=True) + # self.x = self.x.astype('uint8') self.alpha = hp.alpha self.beta = hp.beta @@ -121,7 +124,7 @@ class YourModel(tf.keras.Model): for i in range(len(photo_layers)): pl = photo_layers[i] il = input_layers[i] - L_content = tf.math.add(L_content, tf.reduce_mean(tf.square(pl - il))) + L_content = tf.math.add(L_content, tf.reduce_sum(tf.square(pl - il))) #print('content loss', L_content) return L_content @@ -149,8 +152,10 @@ class YourModel(tf.keras.Model): # get the loss per each lateral layer # N depends on # of filters in the layer, M depends on hight and width of feature map - M_l = art_layer.shape[0] - N_l = art_layer.shape[1] + # M_l = art_layer.shape[0] + # N_l = art_layer.shape[1] + M_l = self.content_image.shape[0]*self.content_image.shape[1] + N_l = art_layer.shape[0] # layer.filters might not work E_l = 1/4 * (M_l**(-2)) *(N_l**(-2)) * tf.reduce_sum(tf.square(G_l - A_l)) @@ -48,6 +48,7 @@ def train(model): model.train_step() def save_image(filename, image): + image = transform.resize(image, tf.shape(image), anti_aliasing=True).astype('uint8') imsave(filename, image) @@ -69,8 +70,9 @@ def main(): train(my_model) final_image = tf.squeeze(my_model.x) + final_image = transform.resize(final_image, tf.shape(final_image), anti_aliasing=True).astype('uint8') - plt.imshow(final_image).astype('uint8') + plt.imshow(final_image) imsave(ARGS.savefile, final_image) |