aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@davids-mbp-3.devices.brown.edu>2022-05-07 18:55:47 -0400
committerDavid Doan <daviddoan@davids-mbp-3.devices.brown.edu>2022-05-07 18:55:47 -0400
commit79e999da9c3eff40006267b53bab0193242322df (patch)
tree3456585b93aa57b5010c3ecee5ff785f547be753
parent7a03723ffb9ac7613f3c5537a4d5c7cb9a4a3f3a (diff)
changes
-rw-r--r--__pycache__/hyperparameters.cpython-38.pycbin0 -> 348 bytes
-rw-r--r--__pycache__/losses.cpython-38.pycbin0 -> 4661 bytes
-rw-r--r--checkpoint-images/img-epoch0.jpgbin0 -> 4723 bytes
-rw-r--r--checkpoint-images/img-epoch100.jpgbin0 -> 114642 bytes
-rw-r--r--checkpoint-images/img-epoch200.jpgbin0 -> 2227 bytes
-rw-r--r--checkpoint-images/img-epoch300.jpgbin0 -> 2227 bytes
-rw-r--r--checkpoint-images/img-epoch400.jpgbin0 -> 2227 bytes
-rw-r--r--hyperparameters.py8
-rw-r--r--losses.py17
-rw-r--r--main.py4
-rw-r--r--save.jpgbin19949 -> 172131 bytes
11 files changed, 19 insertions, 10 deletions
diff --git a/__pycache__/hyperparameters.cpython-38.pyc b/__pycache__/hyperparameters.cpython-38.pyc
new file mode 100644
index 00000000..3162d698
--- /dev/null
+++ b/__pycache__/hyperparameters.cpython-38.pyc
Binary files differ
diff --git a/__pycache__/losses.cpython-38.pyc b/__pycache__/losses.cpython-38.pyc
new file mode 100644
index 00000000..7c0a4b73
--- /dev/null
+++ b/__pycache__/losses.cpython-38.pyc
Binary files differ
diff --git a/checkpoint-images/img-epoch0.jpg b/checkpoint-images/img-epoch0.jpg
new file mode 100644
index 00000000..4836b9e8
--- /dev/null
+++ b/checkpoint-images/img-epoch0.jpg
Binary files differ
diff --git a/checkpoint-images/img-epoch100.jpg b/checkpoint-images/img-epoch100.jpg
new file mode 100644
index 00000000..dfcf28e2
--- /dev/null
+++ b/checkpoint-images/img-epoch100.jpg
Binary files differ
diff --git a/checkpoint-images/img-epoch200.jpg b/checkpoint-images/img-epoch200.jpg
new file mode 100644
index 00000000..13fde882
--- /dev/null
+++ b/checkpoint-images/img-epoch200.jpg
Binary files differ
diff --git a/checkpoint-images/img-epoch300.jpg b/checkpoint-images/img-epoch300.jpg
new file mode 100644
index 00000000..13fde882
--- /dev/null
+++ b/checkpoint-images/img-epoch300.jpg
Binary files differ
diff --git a/checkpoint-images/img-epoch400.jpg b/checkpoint-images/img-epoch400.jpg
new file mode 100644
index 00000000..13fde882
--- /dev/null
+++ b/checkpoint-images/img-epoch400.jpg
Binary files differ
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
diff --git a/losses.py b/losses.py
index 99b1eded..6405df6a 100644
--- a/losses.py
+++ b/losses.py
@@ -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))
diff --git a/main.py b/main.py
index 4497cce0..85ee4862 100644
--- a/main.py
+++ b/main.py
@@ -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)
diff --git a/save.jpg b/save.jpg
index e35f2cbf..cca810d7 100644
--- a/save.jpg
+++ b/save.jpg
Binary files differ