Giter VIP home page Giter VIP logo

mode_collapse's Introduction

Mode Collapse Example

License: MIT

This repository showcases the mode collapse problem of GANs for different loss functions on a 2D toy example distribution.

Standard GAN loss Non-saturating GAN loss Non-saturating GAN loss + top-k Hinge GAN loss Least squares GAN loss
1 2 3 4 5
Wasserstein GAN loss Wasserstein GAN loss + weight clipping Wasserstein GAN loss + spec. norm Wasserstein GAN loss + GP Wasserstein GAN loss + GP + top-k
6 7 8 9 10

Installation

To install all necessary dependencies simply run:

pip install -r requirements.txt

Run Examples

To reproduces the achieved results run the main.py script with the corresponding arguments. Train the discriminater till optimality when using Wasserstein loss by updating it 5 times per generator update leading to more reliable gradients of Wasserstein. Plain Wasserstein requires weight clipping to [-0.01,+0.01] to enforce Lipschitz constraint.

Argument Default value Info
--device 'cuda' Set device to be utilized (cuda or cpu)
--epochs 500 Training epochs to be performed
--d_updates 1 Discriminator updates per generator update
--plot_frequency 10 Frequency of epochs to produce plots
--lr 0.0001 Learning rate to be applied
--latent_size 32 Size of latent vector to be utilized
--samples 10000 Number of samples from the real distribution
--batch_size 500 Batch size to be utilized
--loss 'standard' GAN loss function to be used (standard, non-saturating, hinge, wasserstein, wasserstein-gp or least-squares)
--spectral_norm False If set use spectral norm to stabilize discriminator
--clip_weights 0 If > 0., weights will be clipped to [-clip_weights, +clip_weights]
--topk False If set top-k training is utilized after 0.5 of the epochs to be performed

References

@inproceedings{Goodfellow2014,
    title = {Generative Adversarial Nets},
    author = {Goodfellow, Ian and Pouget-Abadie, Jean and Mirza, Mehdi and Xu, Bing and Warde-Farley, David and Ozair, Sherjil and Courville, Aaron and Bengio, Yoshua},
    booktitle = {Advances in Neural Information Processing Systems},
    volume = {27},
    year = {2014}
}
@inproceedings{Arjovsky2017,
    title={Wasserstein generative adversarial networks},
    author={Arjovsky, Martin and Chintala, Soumith and Bottou, L{\'e}on},
    booktitle={International conference on machine learning},
    pages={214--223},
    year={2017},
    organization={PMLR}
}
@inproceedings{Gulrajani2017,
    title={Improved training of wasserstein GANs},
    author={Gulrajani, Ishaan and Ahmed, Faruk and Arjovsky, Martin and Dumoulin, Vincent and Courville, Aaron},
    booktitle={Proceedings of the 31st International Conference on Neural Information Processing Systems},
    pages={5769--5779},
    year={2017}
}
@article{Lim2017,
    title={Geometric gan},
    author={Lim, Jae Hyun and Ye, Jong Chul},
    journal={arXiv preprint arXiv:1705.02894},
    year={2017}
}
@inproceedings{Mao2017,
    title={Least squares generative adversarial networks},
    author={Mao, Xudong and Li, Qing and Xie, Haoran and Lau, Raymond YK and Wang, Zhen and Paul Smolley, Stephen},
    booktitle={Proceedings of the IEEE international conference on computer vision},
    pages={2794--2802},
    year={2017}
}
@inproceedings{Sinha2020,
    title = {Top-k Training of GANs: Improving GAN Performance by Throwing Away Bad Samples},
    author = {Sinha, Samarth and Zhao, Zhengli and ALIAS PARTH GOYAL, Anirudh Goyal and Raffel, Colin A and Odena, Augustus},
    booktitle = {Advances in Neural Information Processing Systems},
    volume = {33},
    year = {2020}
}

mode_collapse's People

Contributors

christophreich1996 avatar memmelma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mode_collapse's Issues

Issue with the order of the for loops

for _ in range(args.d_updates): # type: int

I wanted to point out a small mistake regarding the for loop of the d_updates. I believe the for loops in the main code are swapped. "for _ in range(args.d_updates)" is intended to update the discriminator several times before updating the generator. However, in the code, it is placed before "for index in range(0, args.samples, args.batch_size)", which is causing the discriminator to be updated int(samples/batch_size) times, and the generator just once.

The correct order should be:

for epoch in range(args.epochs):  # type: int
        # Update progress bar
        progress_bar.update(n=1)
        
        for index in range(0, args.samples, args.batch_size):  # type:int
        
            # Shuffle data
            data = data[torch.randperm(data.shape[0], device=args.device)]
            # Update discriminator more often than generator to train it till optimality 
            for _ in range(args.d_updates):  # type: int

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.