aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__pycache__/losses.cpython-38.pycbin3991 -> 4236 bytes
-rw-r--r--losses.py19
2 files changed, 16 insertions, 3 deletions
diff --git a/__pycache__/losses.cpython-38.pyc b/__pycache__/losses.cpython-38.pyc
index 4fd27000..ebfd7772 100644
--- a/__pycache__/losses.cpython-38.pyc
+++ b/__pycache__/losses.cpython-38.pyc
Binary files differ
diff --git a/losses.py b/losses.py
index a68c6329..2cb51e15 100644
--- a/losses.py
+++ b/losses.py
@@ -12,14 +12,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 = content_image
+ self.content_image = transform.resize(content_image, np.shape(style_image), anti_aliasing=True)
+ self.content_image = np.expand_dims(self.content_image, axis=0)
#perhaps consider cropping to avoid distortion
self.style_image = transform.resize(style_image, np.shape(style_image), anti_aliasing=True)
+ self.style_image = np.expand_dims(self.style_image, axis=0)
self.x = tf.Variable(tf.random.uniform(np.shape(content_image)), trainable=True)
+ self.x = tf.expand_dims(self.x, axis=0)
self.alpha = hp.alpha
self.beta = hp.beta
+ print(self.content_image.shape, self.style_image.shape)
+
self.optimizer = tf.keras.optimizers.RMSprop(learning_rate=hp.learning_rate, momentum=hp.momentum)
self.vgg16 = [
@@ -60,16 +65,19 @@ class YourModel(tf.keras.Model):
activation="relu", name="block5_conv3"),
AveragePooling2D(2, name="block5_pool"),
]
- for layer in self.vgg16:
- layer.trainable = False
+ # for layer in self.vgg16:
+ # layer.trainable = False
self.indexed_layers = [layer for layer in self.vgg16 if layer.name == "conv1"]
+ print(self.indexed_layers)
self.desired = [layer.name for layer in self.vgg16 if layer.name == "conv1"]
def call(self, x):
layers = []
for layer in self.vgg16:
# pass the x through
+ print('this is', x.shape)
+ print(layer.name)
x = layer(x)
# print("Sotech117 is so so sus")
@@ -87,10 +95,12 @@ class YourModel(tf.keras.Model):
content_l = self.content_loss(photo_layers, input_layers)
style_l = self.style_loss(art_layers, input_layers)
# Equation 7
+ print(content_l, style_l)
return (self.alpha * content_l) + (self.beta * style_l)
def content_loss(self, photo_layers, input_layers):
L_content = tf.reduce_mean(tf.square(photo_layers - input_layers))
+ print(L_content)
return L_content
def layer_loss(art_layers, input_layers, layer):
@@ -123,12 +133,15 @@ class YourModel(tf.keras.Model):
L_style = 0
for layer in self.indexed_layers:
L_style += self.layer_loss(art_layers, input_layers, layer)
+ print('this is style loss',L_style)
return L_style
def train_step(self):
with tf.GradientTape() as tape:
loss = self.loss_fn(self.content_image, self.style_image, self.x)
+ print(loss)
gradients = tape.gradient(loss, self.x)
+ print(gradients)
self.optimizer.apply_gradients(zip(gradients, self.x))