Q6 and Q7 In C1W1_Your_First_GAN

Hi

In the test function of Q6,
in test_disc_reasonable. I saw “assert torch.all(torch.abs(disc_loss.mean() - 0.5) < 1e-5)”, this indicates disc_loss should be a tensor.
in test_disc_loss, I saw “assert (disc_loss - 0.68).abs() < 0.05”, this indicates disc_loss should be a scalar.

In the test function of Q7
in test_gen_reasonable, I saw “torch.all(torch.abs(gen_loss_tensor) < 1e-5)”, this indicates the gen_loss should be a tensor.
in test_gen_loss, I saw “assert (gen_loss - 0.7).abs() < 0.1”, this indicates the gen_loss should be a scalar.

I feel it hard to prepare the output dimension to satisfy both test functions.
Can I have some hints on this?

In addition, in test_disc_loss of Q6, criterion is not defined.
I always have trouble with “assert (disc_loss - 0.68).abs() < 0.05” in Q6, and “assert (gen_loss - 0.7).abs() < 0.1” in Q7.
Any hints will be appreciated!

An update. I have figured out the problem.
I accidentally used criterion = torch.mul instead of criterion = nn.BCEWithLogitsLoss().

But I still feel there is a bug.
The output of Q7 is supposed to be a tensor. So I have no idea how to assert (gen_loss - 0.7).abs() < 0.1

Both disc_loss and gen_loss should be tensors in all cases. You then subtract a scalar element-wise (gen_loss - 0.7) and apply an aggregation function such as abs or mean (that is a part of the tensor object) which returns a scalar. In other words, (gen_loss - 0.7) returns a tensor.

1 Like