Week 4 Assignment 2 - compute_layer_style_cost

Hello
W4 Assignment 2, exercise 3 has an additional hints that talks about the shape of unrolled matrix before it’s inputed into the Gram function

Additional Hints

  • Since the activation dimensions are (π‘š,𝑛𝐻,π‘›π‘Š,𝑛𝐢) whereas the desired unrolled matrix shape is (𝑛𝐢,π‘›π»βˆ—π‘›π‘Š), the order of the filter dimension 𝑛𝐢 is changed. So tf.transpose can be used to change the order of the filter dimension.

What happens to the samples after unrolling? shouldn’t it be (nC, nHβˆ—nWβˆ—m)? (nC, nHβˆ—nW) is missing a fourth dimension.

Actually the way the instructions are written is a little misleading. If you actually check how they use compute_layer_style_cost, you’ll find that they only call it for one sample at a time. You can actually add an assertion that m is either 1 or None.

@paulinpaloalto
Thanks for the answer. I am somehow very stuck. I understand that I need to transpose and then reshape. The dimensions work as intended:

The [m, n_H, n_W, n_C] becomes [n_C, n_Hβˆ—n_Wβˆ—m] β€œm is 1”. I used -1 in reshape so it doesn’t matter if m is provided or not. But my final number is very large (2808.4368). I have spent an exorbitant amount of time on this issue to no avail. Could you please take a look at my solution?

Please be aware that the mentors are just fellow student volunteers. We do not have any magic powers to look at anyone else’s notebooks.

Understood. I was just trying to find a way out, didn’t actually thought you can access my file.

I can’t believe my mistake! I forgot that β€œ^” this is NOT power in python. It’s double asterisk **
I spent +12 hrs on this

3 Likes

:scream_cat: :man_facepalming:

Glad to hear you found the answer! If it’s any comfort, there was another thread by someone making that same mistake recently on this very exercise.

Absolutely unbelievable. Thank you so much, anyways.

Damn… I was stuck in exactly the same spot. In fact, I searched the threads for 2808 because that’s exactly the answer I got as well. Thank you so much.

1 Like

thank you. its help me a lot!

I did exactly the same mistake and also had spent a lot of time to find what is the problem. :sweat_smile: