Week 4 assignment 2

I’m getting error in compute_layer_style_cost
when I’m using tf.suare sand tf.multiply its giving tf.float32!=tf.int32:
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.

my code is:
m, n_H, n_W, n_C = a_G.get_shape().as_list()

# Reshape the images to have them of shape (n_C, n_H*n_W) (≈2 lines)
a_S = tf.transpose(tf.reshape(a_S,shape=[n_C,n_H*n_W]))
a_G = tf.transpose(tf.reshape(a_G,shape=[n_C,n_H*n_W]))

# Computing gram_matrices for both images S and G (≈2 lines)
GS = gram_matrix(a_S)
GG = gram_matrix(a_G)

# Computing the loss (≈1 line)
J_style_layer = tf.reduce_sum(tf.square(tf.subtract(GS,GG)))/(4*((n_H*n_W)**2)*((n_C)**2))

Any suggestion will be helpful

Your shape= arguments for both a_S and a_G are incorrect.

The shape shown in the comment instruction seems to be incorrect. See the figure in section 4.2 “Computing the style cost”.

in additional hint it stated that we should take the transpose of it, as reshape always doesn’t lead in required shape i.e. increases layers

I have submitted an issue on this topic for the course staff to look into.

1 Like

As its giving me value of J_style_layer:
tf.Tensor(0.0, shape=(), dtype=float32)
tf.Tensor(29.149204, shape=(), dtype=float32)

but its accepts the value: 14.017805
So, what should I do to pass this statement.

I recommend you write your code so it computes the correct value.

I have written correct code according to me but, if you find any mistake then please correct me.

thanks, for giving me hint for using transpose.
I solved it by changing the dimensions of a_S and a_G.