Week 4, assignment 2 train_step

I did this

        a_G = vgg_model_outputs(generated_image)
        # Compute the style cost
        #(1 line)
        J_style = compute_style_cost(a_S,a_G)

        #(2 lines)
        # Compute the content cost
        J_content = compute_content_cost(a_C, a_G)
        # Compute the total cost
        J = total_cost(J_content, J_style, alpha = 10, beta = 40) 

and am getting an error like this:

ValueError: Cannot reshape a tensor with 48 elements to shape [1,625,512] (320000 elements) for ‘{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](strided_slice_1, Reshape/shape)’ with input shapes: [4,4,3], [3] and with input tensors computed as partial shapes: input[1] = [1,625,512].


can someone help me out?

1 Like

The code you show looks the same as mine, other than that I passed STYLE_LAYERS to the compute_style_cost function. But when I do it the way you show, I don’t get the error messages that you show.

I can only guess that maybe something is wrong with one of your earlier functions. Are you sure you actually looked through the output of all the cells and didn’t just click “Validate”?

I would like to add something to this. I was in a similar situation than @paulinpaloalto and the assert line were wrong but my code was correct. Every time I ran the code, a different value of J appeared!. A simple but efective thing to try is “Restart and Clear Output” and just run again, everything worked.

Note that they tell you that executing the training is “stateful”. Once you’ve run it, you have to reset the train_step cell before you can run it again.