Hi, I am new to pytorch and not quite sure if I am doing right. Please tell me whether the following is right or wrong.
What I am doing:
I am training a GAN. But the generator is a model that learn regression from some prepared input (not random noise). Let’s say we have two model blocks: generator (G) and discriminator (D), and three losses: GAN loss for discriminator (d_loss), GAN loss for generator (g_loss), and regression loss for generator (mse_loss). I would like to update G by combining g_loss and mse_loss.
My question:
It is straightforward to optimize D model, which use GAN loss for discriminator. However, I am not quite sure whether I am doing right. My code is like:
input = ...
regress_label = ...
G = generator()
D = discriminator()
D_optimizer = torch.optim.Adam(D.parameters())
G_optimizer = torch.optim.Adam(G.parameters())
# train G part
g_out = G(input)
d_g_out = D(g_out)
g_loss = loss(d_g_out, tell_D_real)
mse_loss = mse(g_out, regress_label)
# combine GAN loss and regression
total_g_loss = mse_loss + g_loss     # can I just sum them up ???
total_g_loss.backward()
G_optimizer.step()    # update G only relying on optimizer ???

Thank you very much !