diff options
author | Michael Foiani <sotech117@michaels-mbp-4.devices.brown.edu> | 2022-05-10 01:32:39 -0400 |
---|---|---|
committer | Michael Foiani <sotech117@michaels-mbp-4.devices.brown.edu> | 2022-05-10 01:32:39 -0400 |
commit | 8b3745de9f8d411c99ecfc0e3c9b63c7b2a7ac71 (patch) | |
tree | 44325c93b8bd47422b7528a69c19306961a583d0 /model.py | |
parent | c3a8fff5d9465b362214d84d30d9b1212d58722f (diff) |
Add final examples, remove unused data, fix some comments. Good to go :)HEADsubmission
Diffstat (limited to 'model.py')
-rw-r--r-- | model.py | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -11,7 +11,7 @@ class YourModel(tf.keras.Model): super(YourModel, self).__init__() # -------------------------------------------------------------------------------------------------------------- - # PART 1 : preprocess/init the CONTENT, STYLE, and CREATION IMAGES # + # PART 1 : preprocess/init the CONTENT, STYLE, and CREATION IMAGES # -------------------------------------------------------------------------------------------------------------- # 1) resize the content and style images to be the same size self.content_image = transform.resize(content_image, tf.shape(style_image), anti_aliasing=True, @@ -28,7 +28,7 @@ class YourModel(tf.keras.Model): self.x = tf.Variable([image]) # -------------------------------------------------------------------------------------------------------------- - # PART 2 : load and configure vgg_16 network use (without classification head) # + # PART 2 : load and configure vgg_16 network use (without classification head) # -------------------------------------------------------------------------------------------------------------- # 1) load the pretrained vgg_16 network self.vgg16 = tf.keras.applications.VGG16(include_top=False, weights='vgg16_imagenet.h5') @@ -57,7 +57,7 @@ class YourModel(tf.keras.Model): self.vgg16 = tf.keras.Model([self.vgg16.input], [p_output, G]) # -------------------------------------------------------------------------------------------------------------- - # PART 3 : assign our optimizers, loss weights, and loss/style targets # + # PART 3 : assign our optimizers, loss weights, and loss/style targets # -------------------------------------------------------------------------------------------------------------- # 1) use the adam optimizer with hyperparameters defined in the hyperparamters.py self.optimizer = tf.keras.optimizers.Adam(learning_rate=hp.learning_rate, beta_1=hp.beta_1, epsilon=hp.epsilon) @@ -102,7 +102,7 @@ class YourModel(tf.keras.Model): gradients = tape.gradient(loss, self.x) # print the progress of the training and loss - print('\rEpoch {}: Loss: {:.4f}'.format(epoch, loss), end='') + print('\rEpoch {}: Loss: {:.4f}'.format(epoch + 1, loss), end='') # update the optimizer based on the gradients self.optimizer.apply_gradients([(gradients, self.x)]) @@ -130,6 +130,7 @@ class YourModel(tf.keras.Model): @staticmethod def __get_gram(style_output): style_shape = tf.shape(style_output) + # implement the gram matrix using the product of the indices of the equation output = tf.linalg.einsum('bijc,bijd->bcd', style_output, style_output) dimensions = style_shape[1] * style_shape[2] dimensions = tf.cast(dimensions, tf.float32) |