I’m trying to code the ‘graded function’ get_disc_loss(real_X, fake_X, disc_X, adv_criterion), but I’m getting an assertion error and I can’t solve it, so can anyone help me?

Hi @MarcosMM,
You’ve got the basic concepts right - just missing one small thing the assignment is expecting. The unit tests are there to help with this. What I like to do in this situation is to look at the unit test to see what it is expecting and then compare that with what my code returns.

Checking if a value is < 1e-6 is checking that it is very small. Generally, this is used when you expect the value to be close to 0, maybe even exactly 0, but you’re giving a little wiggle room for rounding errors, etc.

If we’re expecting <some_value> - 659054.5 to be close to zero, we’re expecting <some_value> to be close to 659054.5

How does that value compare to the disc_loss you calculated, 1318109.0? Notice anything interesting about how the size of your value compares to the size of the expected value?

Another thing you can look at is to notice the text above this cell of the assignment that says this discriminator loss should be implemented like previous assignments, and then look back at previous assignments, like the week 2 Pix2Pix assignment, to see how they calculate discriminator loss to see how it differs from your current implementation on this assignment.

Thank you very much, as you suggested I have checked the Pix2Pix assignment and I have seen the ‘/2’…

The thing is that I don’t understand why to calculate the average of those two loss values. I don’t know if you could explain it to me. It would be a great help (I don’t like to do things without understanding them ).

Hi @MarcosMM,
There’s not a big reason for it. The most important thing is that we want to minimize loss, and for that, it doesn’t really matter if you ‘/2’ or multiply by 2 or by any other constant.

But the ‘/2’ does have the advantage that it makes the discriminator loss the same scale as the generator loss (generator loss is based on 1 item vs discriminator based on sum of 2 items). Not hugely important, but it does make it easier to compare the two losses when you’re looking at how they’re doing.

That is, it is expecting a loss near 659054 and my losses are near 682000 which means it’s off by a reasonable amount. Not sure what else could be going wrong here.