Last active
October 7, 2018 17:13
-
-
Save danielajisafe/22e94e7e407c330b5811ac88b912f4ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def model_nn(sess, input_image, num_iterations = 200): | |
# Initialize global variables (you need to run the session on the initializer) | |
### START CODE HERE ### (1 line) | |
sess.run(tf.global_variables_initializer()) | |
### END CODE HERE ### | |
# Run the noisy input image (initial generated image) through the model. Use assign(). | |
### START CODE HERE ### (1 line) | |
sess.run(model["input"].assign(input_image)) | |
### END CODE HERE ### | |
for i in range(num_iterations): | |
# Run the session on the train_step to minimize the total cost | |
### START CODE HERE ### (1 line) | |
sess.run(train_step) | |
### END CODE HERE ### | |
# Compute the generated image by running the session on the current model['input'] | |
### START CODE HERE ### (1 line) | |
generated_image = sess.run(model['input']) | |
### END CODE HERE ### | |
# Print every 20 iteration. | |
if i%20 == 0: | |
Jt, Jc, Js = sess.run([J, J_content, J_style]) | |
print("Iteration " + str(i) + " :") | |
print("total cost = " + str(Jt)) | |
print("content cost = " + str(Jc)) | |
print("style cost = " + str(Js)) | |
# save current generated image in the "/output" directory | |
save_image("output/" + str(i) + ".png", generated_image) | |
# save last generated image | |
save_image('output/generated_image.jpg', generated_image) | |
return generated_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment