Art_Generation_with_Neural_Style_Transfer - compute_layer_style_cost


For the UNQ_C3 (compute_layer_style_cost) function, my unit test is failing. I really don’t see anything wrong in the code. It is failing where it is comparing the value the function is computing with the expected value of 14.01. It appears I am getting a different value of 2.92.

My value without the normalization is coming out as 26914. After dividing it by the normalization factor of 9216 (product of 4,n_C,n_C,n_H,n_H,n_W,n_W - using the given formula for the normalization), I am getting the value 2.92. Wondering which piece is wrong here, the 26914 value or the 9216 value!? Please help!! Thank you.

I fixed it, it appears I forgot to use transpose along with reshape. I only used reshape earlier


Congrats that you found the solution under your own power! Thanks for confirming.

Hello there @srikanthm ,

I am facing the same error and saw a couple of people pointing out that the tf.transpose() needs to be used with tf.reshape(). The exercise says to reshape the tensor in this shape.

# Reshape the images to have them of shape (n_C, n_H*n_W) (≈2 lines)

I reshape that in the appropriate format (without transpose) and pass that tensor to gram_matrix() which expects it in that format (n_C, n_H*n_W); however, the code deosn’t work, it says AssertionError: Wrong value.

I don’t seem to understand why do we need to use the tf.transpose() here?

Just reshaping directly to the final shape may or may not give you what you really want. There was an example of this in Course 1 Week 2 when we unrolled the images. Here’s a thread which explains the details in that case. The same idea applies here: if you just directly reshape, you end up scrambling the data. It is essential that you preserve the “channels” dimension in the output.


This was very helpful! Thank you :slight_smile: