jalola / improved-wgan-pytorch

Improved WGAN in Pytorch
MIT License
439 stars 68 forks source link

mone in generator #1

Closed udion closed 6 years ago

udion commented 6 years ago

Hi, In the gan training code, since you have already used gen_cost.backward(mone) for generator, why are you still doing gen_cost = -gen_cost

i.e, should it not be

jalola commented 6 years ago

Hi,

The last gen_cost = -gen_cost does not affect the gradients or the optimizer_g.step() because after backward(), gradients are calculated. It only affects the graph when we draw the gen_cost (It just flips vertically when you're putting - or not putting -)

What matters here is: gen_cost.backward(mone) and disc_cost = disc_fake - disc_real + gradient_penalty disc_cost.backward()

After optimizer.step(), G tries to maximize gen_cost and D tries to minimize disc_fake(kind of gen_cost). So there is a fight between G and D.

udion commented 6 years ago

yes thank you. Tell me though are these 2 equivalent:

jalola commented 6 years ago

thanks too,

That's true

gen_cost = -gen_cost gen_cost.backward()

would result the same.

Nikasa1889 commented 6 years ago

The issue is solved.