# Art Generation with Neural Style Transfef

I’m stuck with Exercise 5 of programming assignment 2 of week 4
I passed all the previous tests. It is showing me this error while implementing the train step function. I am not able to find the mistake.

# UNQ_C5

@tf.function()
def train_step(generated_image):
# In this function you must use the precomputed encoded images a_S and a_C
# Compute a_G as the vgg_model_outputs for the current generated image

``````    ### START CODE HERE

#(1 line)
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 )

### END CODE HERE

generated_image.assign(clip_0_1(generated_image))
return J
``````

Error

tf.Tensor(551.5008, shape=(), dtype=float32)

AssertionError Traceback (most recent call last)
in
5 print(J1)
6 assert type(J1) == EagerTensor, f"Wrong type {type(J1)} != {EagerTensor}"
----> 7 assert np.isclose(J1, 10221.168), f"Unexpected cost for epoch 0: {J1} != {10221.168}"
8
9 J2 = train_step(generated_image)

AssertionError: Unexpected cost for epoch 0: 551.5007934570312 != 10221.168

Hi,

I got the same issue but I have fixed it. The problem is at #UNQ_C3 where you need to put the tf.transpose at somewhere in the reshape function.

4 Likes

It’s either of #UNQ_C3 or #UNQ_C1, it worked for me after fixing these. if possible look at the error trace and which function is leading to the error.

1 Like

If you didn’t find any problems in the previous functions, try to restart the notebook and do all the way down again. If you try this function for several times, since a_S and a_G are lists, it’s likely that some values inside them are modified. So restart all the notebooks from scratch may help.