Week 4 Assignment: Art_Generation_with_Neural_Style_Transfer Issue

Hi,
I am not able to get through this problem and any help around it will be very much appreciated.
While solving the programming assignment, I am getting wrong value for overall cost but all of tests before are working fine. Please check attachments.

Also when I try to Debug by printing individual style and content costs, it end up printing model layer information such as Tensor(“add_4:0”, shape=(), dtype=float32)

Surprisingly it looks like using the tf functions for square and subtraction was generating negative values for Style Cost function. When I replaced these with ** and - operators, and re-running all cells, the issue disappeared.

Previous:
tf.reduce_sum(tf.square(tf.subtract(GS,GG)))/float(4tf.square(n_Hn_W)*tf.square(n_C))

Changed:
J_style_layer = tf.reduce_sum((GS-GG)**2)/float(4*(n_Hn_W)**2n_C**2)

1 Like

The tf functions return tensors. That’s not what you want when computing a scalar value.

You can’t use print() statements for debugging very well, because they just give a summary of the tensor definition when the model is created. Only at runtime can you get real values.