Course 4, week 4 Neural Style Transfer: Error in Compute Content Cost

Can anyone help me with the below error which is thrown when try to execute the 5.5.1 - Compute Content Cost part the “Art Generation with Neural Style Transfer”?

Seems like there is an issue with the compute_content_cost function even though it passes the individual tests as shown below?

1 Like

a_C = vgg_model_outputs(preprocessed_content)
a_G = vgg_model_outputs(generated_image)

You have initialized a_C and a_G in this way only, I suppose?

1 Like

Yes, I have. I think the code you’ve mentioned comes preloaded with the notebook.
So, I haven’t modified the cell as shown below.

I guess your error lies in the compute_content_cost function. When you are initializing a_C_unrolled and a_G_unrolled, you seem to be using content_output and generated_output, and we have to use a_C and a_G instead.

a_C_unrolled = tf.reshape(a_C, shape=[m, -1, n_C])
a_G_unrolled = tf.reshape(a_G, shape=[m, -1, n_C])

Try using these lines of code. I hope it helps


Thanks a lot for your help. That solved it. Appreciate the reply.

I still don’t understand how the test cases were passed.

I guess I have to rely on the ‘submit assignment’ instead of individual test cases for the validity of the function.

Sometimes the test case checks the solution from a single angle and forgets to check from the rest, and hence, as you can see the team keeps on updating the notebooks to include more involved tests.