Course 4, week 4, ex 3, J_style_layer_SG error

—> 11 assert np.isclose(J_style_layer_SG, 14.017805), “Wrong value.”
12
13 print("J_style_layer = " + str(J_style_layer_SG))

AssertionError: Wrong value

my code generates: 2.9203947 , what can be wrong? can you help?

GS:
tf.Tensor(
[[145.15427 -48.84154 -24.277369]
[-48.84154 251.55676 -17.69923 ]
[-24.277369 -17.69923 204.48398 ]], shape=(3, 3), dtype=float32)
GG:
tf.Tensor(
[[ 214.00204 -126.90382 -1.5855498]
[-126.90382 198.78372 27.845083 ]
[ -1.5855498 27.845083 249.46738 ]], shape=(3, 3), dtype=float32)
tf.Tensor(2.9203947, shape=(), dtype=float32)

That is the value that you get if you just directly reshape the a_G and a_S to the final shape that you want. That is a mistake: you need to use transpose in addition to reshape in order to preserve the “channels” dimension. Please have another careful look at the instructions, including the “additional hint”.

For an example of why you can’t just directly reshape to the final shape, here’s a thread explaining a similar situation with reshaping images. It is critical to preserve the “samples” dimension in the image case: just doing the reshape without the transpose ends up scrambling the data. Here’s a better example that is directly relevant to this case here.

4 Likes

thanks , corrected the shape, missed the part that nc,nw*nh order has changed during the flatten operation.

Hello,

I have done the transpose followed by the reshape but I am getting this error:


AssertionError Traceback (most recent call last)
in
9 assert np.isclose(J_style_layer_GG, 0.0), “Wrong value. compute_layer_style_cost(A, A) must be 0”
10 assert J_style_layer_SG > 0, “Wrong value. compute_layer_style_cost(A, B) must be greater than 0 if A != B”
—> 11 assert np.isclose(J_style_layer_SG, 14.017805), “Wrong value.”
12
13 print("J_style_layer = " + str(J_style_layer_SG))

AssertionError: Wrong value.

The value I am getting for a_S and a_G shapes and J_style_layer are:

(3, 16)
(3, 16)
tf.Tensor(0.0, shape=(), dtype=float32)
(3, 16)
(3, 16)
tf.Tensor(918670.8, shape=(), dtype=float32)

It looks like you have an “order of operations” problem with the first factor. Try this and watch what happens:

m = 5
x = 1 / 2 * m
y = 1 / (2 * m)