Question 11
A student is trying to write the Generator training loop and is confused about the order of operations. Their code is:
# --- Training the Generator ---
# 1. Generate fakes and get D's outputz = torch.randn(batch_size, latent_size).to(device)
fake_images = G(z)d_out_fake = D(fake_images)
# 2. Calculate lossg_loss = criterion(d_out_fake, real_labels)
# 3. Update weightsG_optimizer.step() # Line 3ag_loss.backward() # Line 3bG.zero_grad() # Line 3cThis code is completely broken. What is the correct, functional order for lines 3a, 3b, and 3c?