Neural_Style_Transfer Exercise 6 - Cost for Epoch 0 is wrong

All of my tests have passed successfully before exercise 6. I’m getting an error that by Epoch 0 cost is incorrect. Mine is -318755264 and the expected is 25629

I’m pretty sure the function calls in exercise 6 are all correct. I’m trying to understand how I’m getting a negative value and why it is so different?

I’ve already tried restarting the kernel and running all the cells again as suggested in another post.


There is clearly a problem with the loss function because I’m going from the initialized image to garbage in 250 epochs. I’m just not seeing it.

You’re right that the cost should never be negative, so there must be something fundamentally wrong. If all your previous functions pass, the bug could be in train_step.

There are ways to get negative costs due to integer rounding errors. Here’s a thread which shows examples of the issues there, although I think that the current version of TF does not suffer those problems.

I submitted and got 80% so I’m going to run with it. Bummer to hit a bug on the last assignment of the course. I’ve been staring at this for hours and I’m ready for a certificate and a glass of wine.

I think the issue is in compute_layer_style_cost(). I had to explicitly cast the numerator and the denominator to float32 to get it to work. :confused: :confused:

It’s up to you of course, but we can still pursue figuring out the answer even though you’ve already passed the course. It always bugs me when I can explain why my code doesn’t fully work. See your DMs for a message from me about how we could debug further.

Congratulations on finishing the course!

Also note that the thread I linked above was exactly about problems with integer types which can cause negative cost values in compute_layer_style_cost, so that thread would be worth a look.

1 Like

For others reading this … the solution was changing 2 to 2. in the denominator of the compute_layer_style_cost() function. This was not required to pass the test for that function alone but was required to pass exercise 6.

1 Like