Git Product home page Git Product logo

improvedgan-pytorch's Introduction

Improved GAN (Semi-supervised GAN)

This is an implementation of Semi-supervised generative adversarial network in the paper Improved Techniques for Training GANs for Mnist dataset. This method and its extensions have marvellous performance on traditional CV datasets, and remain state-of-art (by the end of November, 2017).

Working Principle

Inspired by Good Semi-supervised Learning that Requires a Bad GAN, semi-supervised GAN with feature matching actually generates unrealistic fake samples around high-density region. With the inborn continuity, the fake region in feature space split the bounds of different classes.

Refer to Semi-supervised Learning on Graphs with Generative Adversarial Nets for more details about this density gap splitting explaination.

Running

The code was implemented in Python 3.7.

python ImprovedGAN.py

Default configs include CPU, saving and autoloading, generating logfile in tensorboard format, etc. You can use python ImprovedGAN.py --cuda to run it on GPU.

The latest torch(1.2 version), tensorboardX, torchvision are needed.

Result

Default configs can train models achieving 98.5% accuracy on test dataset with 100 labeled data(10 per class) and other 59,000 unlabeled data after 100 epochs.

Loss curve during training

loss_label => red, loss_unlabel => blue, loss_gen => green

It must be noted that OpenAI implementation(theano) demonstrates a different curve, where loss_gen is nearly zero and loss_unlabel increase gradually.

Remark

  • The implementation is based on OpenAI implementation.
  • But I found it hard to reproduce expected results and suffered from exploding gradients. I changed the final layer in generator from Sigmoid to Softplus, and therefore fixed it.
  • ./models includes the trained model, you can simply delete it for retraining.
  • The archectures of networks are elaborately designed, among them Weight Normalization is very important.
  • Thank Jiapeng Hong for discussing with me.

Change Logs

  • (Nov 27, 2019) Update to pytorch 1.2 and Python 3.7. The version for pytorch 0.3 and Python 2.7 can be found in the history versions. Delete pretrained models.

improvedgan-pytorch's People

Contributors

dm-thu avatar sleepychord 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

improvedgan-pytorch's Issues

Relation with bad GANs

Hello
You mentioned this code is inspired from the paper called "Good Semi-supervised Learning
That Requires a Bad GAN".

Have you changed any part of "Improved Techniques for Training GANs" to close to bad GANs paper?
What are the exact changes?
It is not clear for me.

Thank you

hello. When the loss_unsupervised is nearly equal with 0, the loss_supervised is still pretty large, how should I do to get better result?

when I run this code, the partial results are as follows.
Iteration 8, loss_supervised = 0.5682, loss_unsupervised = 0.0012, loss_gen = 1.8700 train acc = 0.7541
Eval: correct 6277/ 10000
.......
Iteration 34, loss_supervised = 0.8746, loss_unsupervised = 0.0009, loss_gen = 8.1296 train acc = 0.5644
Eval: correct 8050/ 1800
.......
Iteration 48, loss_supervised = 0.7172, loss_unsupervised = 0.0002, loss_gen = 7.7574 train acc = 0.6869
Eval: correct 8056/ 1800
........
then the results have few change.

change input data

Hello
I tried to feed cifar10, I change the input size to 3072, however in run time I still get
(0): LinearWeightNorm(in_features=784, out_features=1000, weight_scale=1)
(1): LinearWeightNorm(in_features=1000, out_features=500, weight_scale=1)
(2): LinearWeightNorm(in_features=500, out_features=250, weight_scale=1)
(3): LinearWeightNorm(in_features=250, out_features=250, weight_scale=1)
(4): LinearWeightNorm(in_features=250, out_features=250, weight_scale=1)

for first layer it is still 784

AttributeError: 'BatchNorm1d' object has no attribute 'track_running_stats'

I am getting this error:

File "/home/elhamod/melhamodenv/AML/project2/ImprovedGAN-pytorch-master/Nets.py", line 80, in forward
x = F.softplus(self.bn1(self.fc1(x)) + self.bn1_b)
File "/home/elhamod/melhamodenv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/home/elhamod/melhamodenv/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 69, in forward
if self.training and self.track_running_stats:
File "/home/elhamod/melhamodenv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 585, in getattr
type(self).name, name))
AttributeError: 'BatchNorm1d' object has no attribute 'track_running_stats'

Any ideas how to fix it?

the unlabeled samples include the labeled samples

Dear author, thanks for sharing the improved GAN in pytorch. In readme.md, you said: Default configs can train models achieving 98.5% accuracy on test dataset with 100 labeled data(10 per class) and other 59,000 unlabeled data after 100 epochs.
However, according to your implementation, the unlabeled samples are selected as the full train samples of MNIST. It seems they are inconsistent. Which is correct?

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.