I tried reshaping a_G and a_S to just (n_C, n_H*n_W) instead of (_, n_C, n_H * n_W), and got the same InvalidArgument with a different message shown below.
InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:Mul]
I’m missing something here, but don’t know what it is.
So tf.reshape(a_C, shape=[m, n_H * n_W, n_C]) gives the same result as tf.reshape(a_C, shape=[m, -1, n_C]).
this is not the same as your reshaping, can you see you dimensions and the ones suggested here!
The problem is that you are producing 3D tensors after the reshape. What is required are 2D tensors. Here’s the comment in the template code:
# Reshape the tensors from (1, n_H, n_W, n_C) to (n_C, n_H * n_W) (≈2 lines)
It sounds like you already realize the key point that you can’t simply reshape directly to the end shape you want, because it scrambles the values as described on this thread. Read all the way through to see the full explanation.
I added some print statements to my code to show the shapes and here’s what I see when I run the test case there:
Okay, I seemed to have reshaped and transformed successfully since there are no more errors, but I think I am not passing one of the tests because my function is returning the wrong cost value (14.0178 instead of 14.01649)
AssertionError Traceback (most recent call last)
Input In [18], in <cell line: 3>()
1 ### you cannot edit this cell
----> 3 compute_layer_style_cost_test(compute_layer_style_cost)
File /tf/W4A2/public_tests.py:57, in compute_layer_style_cost_test(target)
55 assert np.isclose(J_style_layer_GG, 0.0), “Wrong value. compute_layer_style_cost(A, A) must be 0”
56 assert J_style_layer_SG > 0, “Wrong value. compute_layer_style_cost(A, B) must be greater than 0 if A != B”
—> 57 assert np.isclose(J_style_layer_SG, 14.01649), “Wrong value.”
59 print(“J_style_layer = " + str(J_style_layer_SG))
60 print(”\033[92mAll tests passed")
AssertionError: Wrong value.
What is strange is I noticed I got the same value as Paul in this post.
ah! I finally got all tests to pass. I removed code I had previously typecasting a_S and a_G to double before the gram_matrix function was called because of what appeared to be a typecasting error I was getting before.
Still need to figure out why I was seeing that error before, but now I can move on.