Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a bug about cyclegan? #56

Open
onepeachbiubiubiu opened this issue Jun 19, 2024 · 3 comments
Open

Is there a bug about cyclegan? #56

onepeachbiubiubiu opened this issue Jun 19, 2024 · 3 comments

Comments

@onepeachbiubiubiu
Copy link

I noticed that the training code does not set ‘requires_grad=False’ for the discriminator when training generators, which will conduct gradients to discriminators and force the discriminator to treat the fake image as a 'true image'.

@GaParmar
Copy link
Owner

I am a little confused by this. Could you point to the relevant line in the training code?

Here, the fake image is detached which should stop the flow of gradients:
https://github.com/GaParmar/img2img-turbo/blob/main/src/train_cyclegan_turbo.py#L232

-Gaurav

@onepeachbiubiubiu
Copy link
Author

When training the generator, the discriminator's 'requires_grad' is Ture. So https://github.com/GaParmar/img2img-turbo/blob/main/src/train_cyclegan_turbo.py#L205 will produce gradients for the discriminator. The gradients will update to the discriminator's parameter in https://github.com/GaParmar/img2img-turbo/blob/main/src/train_cyclegan_turbo.py#L238.

@yahshibu
Copy link

yahshibu commented Jun 20, 2024

I think that is the case for train_pix2pix_turbo.py.

Gradients for the discriminator will be produced at

accelerator.backward(lossG)
.
And, the gradients won't be deleted until
optimizer_disc.zero_grad(set_to_none=args.set_grads_to_none)
.

I think
accelerator.unwrap_model(net_disc).requires_grad_(False)
and
accelerator.unwrap_model(net_disc).requires_grad_(True)
should be called at appropriate places.

Thank you for finding this! @onepeachbiubiubiu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants