å®ã¯ãããã©ããã ããã ã£ããããã
- Gãå
ã«Backwardããã¨Dã®.gradã貯ã¾ã
- => "Då ã«å¦ç¿" or "Gã®å¦ç¿æã¯D.requires_grad = false" or "Då¦ç¿åã«NetD.zero_grad()"
- Då¦ç¿æã«G(z)ã渡ãã¨Gã«ã¾ã§Backpropãã¦ç¡é§ & Gã®.gradã貯ã¾ã
- => "D(G(z).detach())" or "Dã®å¦ç¿æã¯G.requires_grad = false" or "Gå¦ç¿åã«NetG.zero_grad()"
- G/Då¦ç¿ã®2åã§ä¸¡æ¹G(z) forwardãã¦ç¡é§ (2 forward pass)
- => "fake = G(z)ã§ä¿æãDã®å¦ç¿ã«D(fake.detach())ãGã®å¦ç¿ã¯D(fake)"
- G forwardæã®requires_gradãå¿ è¦ãªã®ã§requires_gradãããä»ã¨ã®è¡çªã«æ³¨æ
- Gå ã«å¦ç¿ãã㨠fake = G_old(z)ã使ã£ã¦Dãå¦ç¿ãã => fakeåå©ç¨ãªãå¦ç¿ã¯Då Gå¾
- => "fake = G(z)ã§ä¿æãDã®å¦ç¿ã«D(fake.detach())ãGã®å¦ç¿ã¯D(fake)"
æ¨æºå®è£ #1: DCGAN - PyTorch official (tutorial, repository)
æ¨æºå®è£ #1pl: Vanilla GAN - PyTorch Lightning
fakeä¿æ
ç´ ç´ã¨ããã°ç´ ç´ã ãã©ãæ½è±¡åã¯ãã¥ããå¦ç.
PyTorch-Lightningã¨ãã ã¨ç´ ç´ã«ã¯ä½¿ããªãï¼backwardå¨ããã¹ã¦èªåå¦çãå¿
è¦ï¼.
åæ¸é
10%ãããè¨ç®éãæ¸ã (9 step => 8 step).
Gãéãã¨å¹æã大ãããªããã
# D training ## forward G(z) => fake D(fake) D(real) ## backward D(fake) D(real) # G training ## forward G(z) => fake (ããã ãçç¥ã§ããï¼ D(fake) ## backward D(fake) G(z)
ãã£ããã¨ã ãç解ãã¦ãããã®
separate mini-batch: ãããåä½ã®å¦çã¯Realå
ãFakeå
ã§ãããªãããã«ãã
ä¾: (loss(D(real)) + loss(D(fake))).backward()ããã¨ä¸¡æ¹ã®batchã®lossãBatchNormã«æµãè¾¼ã¿ããããå
çµ±è¨ãreal/fakeãã¡ãæ··ãã«ãªã.
Now, with the gradients accumulated from both the all-real and all-fake batches, we call a step of the Discriminatorâs optimizer.