Skip to content

Instantly share code, notes, and snippets.

@Yuvnish017
Created June 24, 2021 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuvnish017/6c76ba40614904c73405960c8b9e1175 to your computer and use it in GitHub Desktop.
Save Yuvnish017/6c76ba40614904c73405960c8b9e1175 to your computer and use it in GitHub Desktop.
optimizer = keras.optimizers.SGD(
keras.optimizers.schedules.ExponentialDecay(
initial_learning_rate=100.0, decay_steps=500, decay_rate=0.96
)
)
base_image = preprocess_image('yuvnish malhotra photo.jpg')
style_reference_image = preprocess_image('style_image3.jpg')
combination_image = tf.Variable(preprocess_image('yuvnish malhotra photo.jpg'))
print(base_image.shape)
print(style_reference_image.shape)
print(combination_image.shape)
losses = []
iter = []
# combination_image = tf.Variable(content_img)
iterations = 8000
for i in range(1, iterations + 1):
loss, grads = compute_loss_and_grads(
combination_image, base_image, style_reference_image
)
optimizer.apply_gradients([(grads, combination_image)])
losses.append(loss)
iter.append(i)
if i % 100 == 0:
print("Iteration %d: loss=%.2f" % (i, loss))
if i == 8000:
img = deprocess_image(combination_image.numpy())
fname = result_prefix + "_at_iteration_%d.png" % i
# keras.preprocessing.image.save_img(fname, img)
cv2.imwrite(fname, img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment