in test_gen_loss(num_images)
35
36 # Check that the loss is reasonable
—> 37 assert (gen_loss - 0.7).abs() < 0.1
38 gen_loss.backward()
39 old_weight = gen.gen[0][0].weight.clone()
Let’s compare the assignment’s instructions to what you’ve done:
# These are the steps you will need to complete:
# 1) Create noise vectors and generate a batch of fake images.
# Remember to pass the device argument to the get_noise function.
Sounds good, you have your noise vectors (noise_input) and your batch of fake images (fake_images).
# 2) Get the discriminator's prediction of the fake image.
That’s your fake_pred alright, though I don’t think you need to detach fake_images here.
# 3) Calculate the generator's loss. Remember the generator wants
# the discriminator to think that its fake images are real
# *Important*: You should NOT write your own loss function here - use criterion(pred, true)!
Now for the final generator’s loss, we want the discriminator to think the fake images are real, i.e. we want the ground truth to be all ones. Remember this is the generator’s loss: the generator wants to fool the discriminator, which would mean the discriminator saying an image is real when in reality it is fake.
Also, mind the order of criterion's arguments: it should be the prediction first, then this ground truth, i.e. criterion(pred, true).
Hope this helps you pass the unit tests. Cheers, and welcome to the community!
Very helpful, thank you so much! I completely missed the hint “Remember the generator wants
the discriminator to think that its fake images are real”.