GithubHelp home page GithubHelp logo

znxlwm / pytorch-mnist-celeba-cgan-cdcgan Goto Github PK

View Code? Open in Web Editor NEW
465.0 11.0 127.0 46.78 MB

Pytorch implementation of conditional Generative Adversarial Networks (cGAN) and conditional Deep Convolutional Generative Adversarial Networks (cDCGAN) for MNIST dataset

Python 100.00%
pytorch cgan cdcgan generative-adversarial-network conditional-gan conditional-dcgan mnist celeba gender

pytorch-mnist-celeba-cgan-cdcgan's Introduction

pytorch-MNIST-CelebA-cGAN-cDCGAN

Pytorch implementation of conditional Generative Adversarial Networks (cGAN) [1] and conditional Generative Adversarial Networks (cDCGAN) for MNIST [2] and CelebA [3] datasets.

Implementation details

  • cGAN

GAN

  • cDCGAN

Loss

Resutls

MNIST

  • Generate using fixed noise (fixed_z_)
cGAN cDCGAN
  • MNIST vs Generated images
MNIST cGAN after 50 epochs cDCGAN after 20 epochs
  • Learning Time
    • MNIST cGAN - Avg. per epoch: 9.13 sec; Total 50 epochs: 937.06 sec
    • MNIST cDCGAN - Avg. per epoch: 47.16 sec; Total 20 epochs: 1024.26 sec

CelebA

  • Generate using fixed noise (fixed_z_; odd line - female (y: 0) & even line - male (y: 1); each two lines have the same style (1-2) & (3-4).)
cDCGAN cDCGAN crop
  • CelebA vs Generated images
CelebA cDCGAN after 20 epochs cDCGAN crop after 30 epochs
  • CelebA cDCGAN morphing (noise interpolation)
cDCGAN cDCGAN crop
  • Learning Time
    • CelebA cDCGAN - Avg. per epoch: 826.69 sec; total 20 epochs ptime: 16564.10 sec

Development Environment

  • Ubuntu 14.04 LTS
  • NVIDIA GTX 1080 ti
  • cuda 8.0
  • Python 2.7.6
  • pytorch 0.1.12
  • torchvision 0.1.8
  • matplotlib 1.3.1
  • imageio 2.2.0

Reference

[1] Mirza, Mehdi, and Simon Osindero. "Conditional generative adversarial nets." arXiv preprint arXiv:1411.1784 (2014).

(Full paper: https://arxiv.org/pdf/1411.1784.pdf)

[2] Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. "Gradient-based learning applied to document recognition." Proceedings of the IEEE, 86(11):2278-2324, November 1998.

[3] Liu, Ziwei, et al. "Deep learning face attributes in the wild." Proceedings of the IEEE International Conference on Computer Vision. 2015.

pytorch-mnist-celeba-cgan-cdcgan's People

Contributors

znxlwm 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

pytorch-mnist-celeba-cgan-cdcgan's Issues

niu bi

代码直接cuda,不考虑cpu的情况。而且还一堆错误,这种代码为啥

Question about mnist-cDCGAN

I notice that you use "y_ = (torch.rand(mini_batch, 1) * 10).type(torch.LongTensor).squeeze()" in line 235,why not use the real y_ from input image?

miss of files

There are no files named "Fixed_results", it seems that some files are missed

ERROR

ValueError: Using a target size (torch.Size([128])) that is different to the input size (torch.Size([128, 6, 6])) is deprecated. Please ensure they have the same size.

the loss of Generator didn't decrease

I only changed one place
transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))
to transforms.Normalize((0.1307,), (0.3081,))
because it causes error.
following is trainning process:
[1/50] - ptime: 29.42, loss_d: 0.855, loss_g: 1.262
[2/50] - ptime: 29.97, loss_d: 0.288, loss_g: 2.511
[3/50] - ptime: 31.54, loss_d: 0.090, loss_g: 3.608
[4/50] - ptime: 32.44, loss_d: 0.086, loss_g: 4.054
[5/50] - ptime: 34.58, loss_d: 0.070, loss_g: 4.227
[6/50] - ptime: 32.97, loss_d: 0.033, loss_g: 4.767
[7/50] - ptime: 33.55, loss_d: 0.014, loss_g: 5.374
[8/50] - ptime: 34.24, loss_d: 0.029, loss_g: 5.416
[9/50] - ptime: 34.68, loss_d: 0.008, loss_g: 5.843
[10/50] - ptime: 35.56, loss_d: 0.016, loss_g: 5.878
[11/50] - ptime: 38.06, loss_d: 0.006, loss_g: 6.242
[12/50] - ptime: 34.45, loss_d: 0.026, loss_g: 6.199
[13/50] - ptime: 32.97, loss_d: 0.005, loss_g: 6.561
[14/50] - ptime: 32.59, loss_d: 0.015, loss_g: 6.542
[15/50] - ptime: 32.66, loss_d: 0.002, loss_g: 6.981
[16/50] - ptime: 32.96, loss_d: 0.025, loss_g: 6.400
[17/50] - ptime: 33.44, loss_d: 0.019, loss_g: 6.936
[18/50] - ptime: 33.80, loss_d: 0.008, loss_g: 6.489
[19/50] - ptime: 34.30, loss_d: 0.002, loss_g: 7.097
[20/50] - ptime: 34.98, loss_d: 0.040, loss_g: 6.319
[21/50] - ptime: 34.86, loss_d: 0.003, loss_g: 6.906
[22/50] - ptime: 34.65, loss_d: 0.003, loss_g: 7.332
[23/50] - ptime: 34.74, loss_d: 0.008, loss_g: 7.447
[24/50] - ptime: 34.87, loss_d: 0.003, loss_g: 7.552
[25/50] - ptime: 34.79, loss_d: 0.001, loss_g: 7.913
[26/50] - ptime: 35.62, loss_d: 0.009, loss_g: 7.999
[27/50] - ptime: 37.91, loss_d: 0.006, loss_g: 7.409
[28/50] - ptime: 33.79, loss_d: 0.001, loss_g: 8.188
[29/50] - ptime: 32.57, loss_d: 0.001, loss_g: 8.127
learning rate change!
[30/50] - ptime: 32.99, loss_d: 0.005, loss_g: 7.739
[31/50] - ptime: 33.69, loss_d: 0.001, loss_g: 7.975
[32/50] - ptime: 34.34, loss_d: 0.001, loss_g: 8.114
[33/50] - ptime: 35.43, loss_d: 0.001, loss_g: 8.140
[34/50] - ptime: 36.85, loss_d: 0.002, loss_g: 7.763
[35/50] - ptime: 40.14, loss_d: 0.001, loss_g: 8.218
[36/50] - ptime: 44.25, loss_d: 0.001, loss_g: 8.467
[37/50] - ptime: 45.44, loss_d: 0.001, loss_g: 8.708
[38/50] - ptime: 40.60, loss_d: 0.001, loss_g: 8.666
[39/50] - ptime: 40.33, loss_d: 0.001, loss_g: 8.824
learning rate change!
[40/50] - ptime: 39.38, loss_d: 0.000, loss_g: 8.775
[41/50] - ptime: 37.45, loss_d: 0.000, loss_g: 8.842
[42/50] - ptime: 37.45, loss_d: 0.001, loss_g: 8.971
[43/50] - ptime: 38.80, loss_d: 0.001, loss_g: 8.718
[44/50] - ptime: 38.23, loss_d: 0.000, loss_g: 8.672
[45/50] - ptime: 40.54, loss_d: 0.000, loss_g: 8.708
[46/50] - ptime: 36.43, loss_d: 0.000, loss_g: 8.707
[47/50] - ptime: 34.01, loss_d: 0.000, loss_g: 8.800
[48/50] - ptime: 36.30, loss_d: 0.000, loss_g: 8.910
[49/50] - ptime: 36.61, loss_d: 0.000, loss_g: 8.990
[50/50] - ptime: 35.31, loss_d: 0.000, loss_g: 9.075
Avg one epoch ptime: 35.55, total 50 epochs ptime: 1881.31
Training finish!... save training results

[solved] wrong MNIST format

error:
RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

MNIST has [1, 28, 28] and [3. 28. 28] two format. In this code,
change
transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))
to
transforms.Normalize([0.5], [0.5])

How to pass custom dataset?

Can Anybody please help how to pass custom datasets instead of MNIST?

train_loader = torch.utils.data.DataLoader( datasets.MNIST('data', train=True, download=False, transform=transform), batch_size=batch_size, shuffle=True)

Discriminator Over-fitting Issue

Hello,

Thanks for sharing your implementation of cDCGAN.

I have tried implementing it for MNIST data set following the same steps you did in 'pytorch_MNIST_cDCGAN.py' with same parameter settings except for the batch size (I used 32 instead of 128). Unfortunately, I get unstable results for epochs larger than 5.

Based on your implementation, I cannot find something like label smoothing or arbitrary Gaussian noise addition to the discriminator input images in order to fix the over fitting issues as described here. Have you already used such stabilizing tricks and I couldn't observe in your implementation ?

With many thanks in advance

Best

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.