C4 Week 4 Exercise 6 - train_step

I have some problems with exercise 6, the train_step function.

I get no error message, but every time I run the function I get new tensor values that do not correspond to the solution. For instance:

tf.Tensor(25700.293, shape=(), dtype=float32)
tf.Tensor(17777.773, shape=(), dtype=float32)

I expect the error is in one of the previous functions. But all pass the test and pass the grader function.

I do not really know where to look. Thank you for your help.

@lindhard

Share the screenshot of the error you are encountering without sharing any part of the grade cell codes.

Regards
DP

What does the grader say if you submit your code?

One thing to note is that the train_step function is stateful: you canā€™t just run the test cell multiple times. If you want consistent results, you have to start by running the train_step cell itself.

Your values are actually relatively close. It could be different rounding behavior caused by numerical stability issues. It might be worth having a look at this thread.

I have no error. I states it passes, even though the tensor values are wrong. When I submit it for grading it does not pass.

Everything runs :slight_smile:

Thanks for your input. It makes sense, just have to figure out where the problem is, as everything runs :slight_smile:

The grader says that it is wrong.
I can run everything and even generate fine pictures.
It is a little hard to know where the error is as i get no error message.

It is probably time to look at the code, but we canā€™t do that on a public thread. I will send you a DM ā€¦

you need to share screenshot of your submission grade where it provides information about the reason why it failed, click on show grader output and then take screenshot.

Code Cell UNQ_C1: Function ā€˜compute_content_costā€™ is correct.
Code Cell UNQ_C2: Function ā€˜gram_matrixā€™ is correct.
Code Cell UNQ_C3: Function ā€˜compute_layer_style_costā€™ is correct.
Code Cell UNQ_C4: Function ā€˜total_costā€™ is correct.
Code Cell UNQ_C5: Function ā€˜train_stepā€™ is incorrect. Check implementation.
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.
This dependency may be the cause of the errors.

In UNQ_CI i get a roundet of number:

Not sure if that is the problem.
J_content = tf.Tensor(7.056877, shape=(), dtype=float32) All tests passed

Expected Output:

J_content 7.0568767

Regarding UNQ_C5 i get:

tf.Tensor(25700.293, shape=(), dtype=float32) tf.Tensor(17777.783, shape=(), dtype=float32) All tests passed

Expected output

tf.Tensor(25700.346, shape=(), dtype=float32)
tf.Tensor(17778.389, shape=(), dtype=float32)

But they vary a little

To close the loop on the public thread, there was a bug in train_step. The logic used a_S as the input image for both the style cost and the content cost. Probably a classic ā€œcopy/pasteā€ error.

The scarier point is that the tests in the notebook do not catch this error, although the grader does.

1 Like

Improving the unit tests is always in-fashion.

1 Like