Art Generation with Neural Style Transfer ex-6

I have a problem in compute_style_cost(style_image_output, generated_image_output, STYLE_LAYERS=STYLE_LAYERS) and compute_content_cost(content_output, generated_output) … what should be the args given to the function … I think the generated output is a_G which computed as follows a_G=vgg_model_outputs(generated_image) … if I’m right what should be the rest of arguments ?

For compute_style_cost the arguments are a_S and a_G. You can pass the STYLE_LAYERS argument as well if you like, but it defaults to the correct value.

For compute_content_cost, the arguments are a_C and a_G.

What is the indication of error that you are getting?

this is my error … after using compute_style_cost() and compute_content_cost() with the correct arguments "AssertionError Traceback (most recent call last)
Input In [59], in <cell line: 7>()
1 ### you cannot edit this cell
2
3 # You always must run the last cell before this one. You will get an error if not.
5 generated_image = tf.Variable(generated_image)
----> 7 train_step_test(train_step, generated_image)

File /tf/W4A2/public_tests.py:89, in train_step_test(target, generated_image)
87 print(J1)
88 assert type(J1) == EagerTensor, f"Wrong type {type(J1)} != {EagerTensor}"
—> 89 assert np.isclose(J1, 25629.055, rtol=0.05), f"Unexpected cost for epoch 0: {J1} != {25629.055}"
91 J2 = target(generated_image)
92 print(J2)

AssertionError: Unexpected cost for epoch 0: 6425.390625 != 25629.055"
I used this line “a_G = vgg_model_outputs(generated_image)” to get a_G and I computed total cost as follow J=(10xJ_style)+(40xJ_content) … I can’t find the wrong part in my code.

There are some quirky “statefulness” properties of the way they have written the code here. One thing to try is to start everything from a clean state:

Kernel → Restart and Clear Output
Cell → Run All

Then see if your results match the expected. Please try that and let us know what happens.

One other thing to note is that you don’t have to manually compute the total cost, right? There’s a function for that.

You should compute J by calling the total_cost() function.

1 Like

thanks for your helpful hints … I made it :innocent:

@TMosh @paulinpaloalto

2 Likes