Hello to anyone who is reading this, I am facing the following error.
Don’t use the numpy API inside compute_layer_style_cost
Failed to convert object of type <class ‘list’> to Tensor. Contents: [None, 16, 8]. Consider casting elements to a supported type.
This error corresponds to the following code:
UNQ_C3
GRADED FUNCTION: compute_layer_style_cost
def compute_layer_style_cost(a_S, a_G):
“”"
Arguments:
a_S – tensor of dimension (1, n_H, n_W, n_C), hidden layer activations representing style of the image S
a_G – tensor of dimension (1, n_H, n_W, n_C), hidden layer activations representing style of the image G
Returns:
J_style_layer -- tensor representing a scalar value, style cost defined above by equation (2)
"""
### START CODE HERE
# Retrieve dimensions from a_G (≈1 line)
m, n_H, n_W, n_C = a_G.get_shape().as_list()
# Reshape the images from (n_H * n_W, n_C) to have them of shape (n_C, n_H * n_W) (≈2 lines)
a_S = tf.transpose(tf.reshape(a_S, shape = [m, n_H * n_W, n_C]), perm = [0,2,1]) # '0' is the batch, so, you transpose the other two dimensions
a_G = tf.transpose(tf.reshape(a_G, shape = [m, n_H * n_W, n_C]), perm = [0,2,1])
# 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 = (1/(4*(n_C**2)*((n_H*n_W)**2))) * tf.math.reduce_sum(tf.math.square(tf.subtract(GS, GG)), axis=None, keepdims=False)
### END CODE HERE
return J_style_layer
I review the code and I think everything (including the dimensions) is ok, I have no idea where the error could be, I read another post about this same topic but it wasn’t too explicit, so, my code is here, feel free to remove the code once anyone can give me the possible solution.
thanks in advance to the person who is reading this right now and trying to figure out my error.
##########
Update
##########
I submitted the exercise and I got 100/100, so, I don’t know what the meaning of the error is.