junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
22.66k stars 6.27k forks source link

Differentiable data augmentation #1081

Open Rubiel1 opened 4 years ago

Rubiel1 commented 4 years ago

There is a new paper on differentiable data augmentation for GANS: https://arxiv.org/pdf/2006.10738.pdf, it seems promising.

I have implemented it on pix2pix. For any one interested, I added:

the file to the folder utils.

parser.add_argument('--dif_data_augm', type=str, default='', help='differential data augmentation currenly only for pix2pix models. [color | translation | cutout | color,cutout|...|color,translation,cutout]') here ,

from util.DiffAugment_pytorch import DiffAugment here

`

specify the smooth data augmentation, default is none, options include translation, change on color and random cutout

    self.dif_data_augm = opt.dif_data_augm`

here

`

smooth data aumentation policy

    policy = self.dif_data_augm`

here

I replaced this by

` fake_AB = DiffAugment(fake_AB.detach(), policy=policy) # by default we don't modify the data

    pred_fake = self.netD(fake_AB)

    self.loss_D_fake = self.criterionGAN(pred_fake, False)`

Also this by ` policy = self.dif_data_augm

    # First, G(A) should fake the discriminator

   fake_AB = DiffAugment(fake_AB, policy=policy)

   pred_fake = self.netD(fake_AB) `

and this by

`
real_AB = DiffAugment(real_AB, policy=policy)

    pred_real = self.netD(real_AB)  # by default we don't modify the data`
junyanz commented 4 years ago

Great. Does it help in your experiments? Maybe @zsyzzsoft can help create a PR or a branch for all the models. We are doing some experiments with conditional GANs and standard datasets, and considering adding them to arXiv v2.

Rubiel1 commented 4 years ago

I was missing one line, so I updated my original comment. I found that this helps to prevent the discriminator to overfit. But I was missing one line so I have to repeat the experiments.