Coder Social home page Coder Social logo

se11en / glsgan-gp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maple-research-lab/glsgan-gp

0.0 1.0 0.0 1.88 MB

Generalized Loss-Sensitive Generative Adversarial Networks (GLS-GAN) in PyTorch with gradient penalty, including both LS-GAN and WGAN as special cases.

Home Page: http://www.cs.ucf.edu/%7Egqi/GANs.htm

Python 100.00%

glsgan-gp's Introduction

Generalized Loss-Sensitive GAN

Framework: Pytorch 0.2.0.post1 or above

Language: Python 2.7 or above

Implemented by: Zihang Zou, [Laboratory for MAchine Perception and Learning(MAPLE)], University of Central Florida

Please cite the following paper when referring to the following algorithms:

Guo-Jn Qi. Loss-Sensitive Generative Adversarial Networks on Lipschitz Densities. arXiv:1701.06264 [pdf]

Reference

LS-GAN

Code: https://github.com/guojunq/lsgan

Paper: https://arxiv.org/pdf/1701.06264

GLS-GAN (Generalized Loss-Sensitive GAN)

This project implements the algorithms proposed in generalized loss-sensitive GAN (GLS-GAN), which includes both conventional LS-GAN and WGAN as special cases. The loss sensitive gan regularizes GAN on Lipschitz density through a margin and well defined discrminator output. LSGAN abandons the the binary entropy term proposed in classic GAN and apply the assumption that a real example should have a smaller loss than a generated sample.

Training Objctives and Cost Function for GLS-GAN

Discrmintor loss and generator loss for GLS-GAN are as below:

D_loss = LeakyReLU(D(x) - D(G(z)) + lambda * \delta(x, G(z))).mean()

G_loss = D(G(z)).mean()

It's worth noting that we use LeakyReLU as the cost function for GLS-GAN.

By setting the slope in LeakyReLU to 0, the GLS-GAN becomes LS-GAN; Otherwise, by setting the slope to 1, the GLS-GAN becomes WGAN.

Thus, GLS-GAN is a more general regularized GAN model, which has better generalization performance than both LS-GAN and WGAN by choosing a proper cost function. More details can be found in the paper.

Gradient Penalty

The gradient penalty applies the form proposed originally in the first version of LS-GAN, Chapter 5 [pdf], quoted here "Alternatively, one may consider to directly minimize the gradient norm ||∇xLθ(x)|| as a regularizer for the LS-GAN. In this paper, we adopt weight decay for its simplicity and find it works well with the LS-GAN model in experiments."

Usage

1.PYTORCH version

1.In this implementation, we use the following version of PYTORCH (any version beyond this will also work),

$ pip list | grep torch
torch (0.2.0.post1)
torchvision (0.1.8)

We use the following function to calculate the gradient penalty. torch.autograd.grad() [source]

2.Download dataset

1.Setup and download celebA dataset

Download img_align_celeba.zip from http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html under the link "Align&Cropped Images".

2.Crop the face using face detector.

$ python ./Data/face_detect.py

Note: For those dataset that are not supported by PYTORCH, you can use your own image folder by using the parameter --dataset folder, the code will work. And be sure to have a sub-folder under the main images folder. For example, celebA_crop/64_crop/.

3.Train LS-GAN

The default slope is 0, which is LS-GAN,

$ python lsgan-gp.py --dataset folder --dataroot celebA_crop --cuda --niter 25

If slope is set to 1, it is WGAN,

$ python lsgan-gp.py --dataset folder --dataroot celebA_crop --cuda --niter 25 --slope 1

Or you can explore more slope as GLS-GAN, for example,

$ python lsgan-gp.py --dataset folder --dataroot celebA_crop --cuda --niter 25 --slope 0.01

Results

We save our generated images in samples folder using torchvision.utils.save_image function. You should get the following results after running the code.

LSGAN converges faster! You can start getting recognizable results after half an epoch.

half epoch

alt text

1 epoch

alt text

2 epoch

alt text

3 epoch

alt text

5 epoch

alt text

10 epoch

alt text

15 epoch

alt text

20 epoch

alt text

25 epoch

alt text

glsgan-gp's People

Contributors

zzzucf avatar guojunq avatar

Watchers

James Cloos avatar

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.