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
GRADED FUNCTION: train_step
optimizer = tf.keras.optimizers.Adam(learning_rate=0.03)
@tf.function()
def train_step(generated_image):
with tf.GradientTape() as tape:
# 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
grad = tape.gradient(J, generated_image)
optimizer.apply_gradients([(grad, generated_image)])
generated_image.assign(clip_0_1(generated_image))
# For grading purposes
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