Collection of generative models in Pytorch version.

Overview

pytorch-generative-model-collections

Original : [Tensorflow version]

Pytorch implementation of various GANs.

This repository was re-implemented with reference to tensorflow-generative-model-collections by Hwalsuk Lee

I tried to implement this repository as much as possible with tensorflow-generative-model-collections, But some models are a little different.

This repository is included code for CPU mode Pytorch, but i did not test. I tested only in GPU mode Pytorch.

Dataset

  • MNIST
  • Fashion-MNIST
  • CIFAR10
  • SVHN
  • STL10
  • LSUN-bed

I only tested the code on MNIST and Fashion-MNIST.

Generative Adversarial Networks (GANs)

Lists (Table is borrowed from tensorflow-generative-model-collections)

Name Paper Link Value Function
GAN Arxiv
LSGAN Arxiv
WGAN Arxiv
WGAN_GP Arxiv
DRAGAN Arxiv
CGAN Arxiv
infoGAN Arxiv
ACGAN Arxiv
EBGAN Arxiv
BEGAN Arxiv

Variants of GAN structure (Figures are borrowed from tensorflow-generative-model-collections)

Results for mnist

Network architecture of generator and discriminator is the exaclty sames as in infoGAN paper.
For fair comparison of core ideas in all gan variants, all implementations for network architecture are kept same except EBGAN and BEGAN. Small modification is made for EBGAN/BEGAN, since those adopt auto-encoder strucutre for discriminator. But I tried to keep the capacity of discirminator.

The following results can be reproduced with command:

python main.py --dataset mnist --gan_type <TYPE> --epoch 50 --batch_size 64

Fixed generation

All results are generated from the fixed noise vector.

Name Epoch 1 Epoch 25 Epoch 50 GIF
GAN
LSGAN
WGAN
WGAN_GP
DRAGAN
EBGAN
BEGAN

Conditional generation

Each row has the same noise vector and each column has the same label condition.

Name Epoch 1 Epoch 25 Epoch 50 GIF
CGAN
ACGAN
infoGAN

InfoGAN : Manipulating two continous codes

All results have the same noise vector and label condition, but have different continous vector.

Name Epoch 1 Epoch 25 Epoch 50 GIF
infoGAN

Loss plot

Name Loss
GAN
LSGAN
WGAN
WGAN_GP
DRAGAN
EBGAN
BEGAN
CGAN
ACGAN
infoGAN

Results for fashion-mnist

Comments on network architecture in mnist are also applied to here.
Fashion-mnist is a recently proposed dataset consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. (T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag, Ankle boot)

The following results can be reproduced with command:

python main.py --dataset fashion-mnist --gan_type <TYPE> --epoch 50 --batch_size 64

Fixed generation

All results are generated from the fixed noise vector.

Name Epoch 1 Epoch 25 Epoch 50 GIF
GAN
LSGAN
WGAN
WGAN_GP
DRAGAN
EBGAN
BEGAN

Conditional generation

Each row has the same noise vector and each column has the same label condition.

Name Epoch 1 Epoch 25 Epoch 50 GIF
CGAN
ACGAN
infoGAN

InfoGAN : Manipulating two continous codes

All results have the same noise vector and label condition, but have different continous vector.

Name Epoch 1 Epoch 25 Epoch 50 GIF
infoGAN

Loss plot

Name Loss
GAN
LSGAN
WGAN
WGAN_GP
DRAGAN
EBGAN
BEGAN
CGAN
ACGAN
infoGAN

Folder structure

The following shows basic folder structure.

├── main.py # gateway
├── data
│   ├── mnist # mnist data (not included in this repo)
│   ├── ...
│   ├── ...
│   └── fashion-mnist # fashion-mnist data (not included in this repo)
│
├── GAN.py # vainilla GAN
├── utils.py # utils
├── dataloader.py # dataloader
├── models # model files to be saved here
└── results # generation results to be saved here

Development Environment

  • Ubuntu 16.04 LTS
  • NVIDIA GTX 1080 ti
  • cuda 9.0
  • Python 3.5.2
  • pytorch 0.4.0
  • torchvision 0.2.1
  • numpy 1.14.3
  • matplotlib 2.2.2
  • imageio 2.3.0
  • scipy 1.1.0

Acknowledgements

This implementation has been based on tensorflow-generative-model-collections and tested with Pytorch 0.4.0 on Ubuntu 16.04 using GPU.

Comments
  • Doubt in ACGAN

    Doubt in ACGAN

    Hi

    Thanks for your wonderful code. I read the ACGAN paper and your implementation. I have a query, in the schematic diagram you have shown that c is used along-with x in the Discriminator D. However, in the code, you have not used the class information c while training the D and G(z) as you have done in CGAN ?

    [1] Is it wrong to use the class information in the discriminator process ? [2] If it is not required then shouldn't the variable y_fill_ removed ? It seems to be redundant in this case.

    Also for the C_fake_loss can we use some random labels or is it required to use those labels that have been sampled from the data_loader (like you have done) ?

    Thanks in advance !

    opened by devraj89 3
  • Why do we need to call net.train() in ACGAN?

    Why do we need to call net.train() in ACGAN?

    In many places like here and here, we have D.train() and G.train(). Is there any particular reason that we need to explicitly set them as True (over and over again) ? The official Pytorch GAN example doesn't seem to do net.train() at all. Thanks!

    opened by haoyangz 1
  • Can only load mnist dataset

    Can only load mnist dataset

    Thanks for this cool codebase that allows one to use many GANs!

    But it seems that only the mnist dataset can be loaded, because the other functions are missing from the utils module. For example, if I issue this command:

    python main.py --dataset celebA --gan_type WGAN --epoch 25 --batch_size 64
    

    This results in the traceback:

    Traceback (most recent call last):                                                                          │·····
     File "main.py", line 107, in <module>                                                                     │·····
        main()                                                                                                  │·····
      File "main.py", line 86, in main                                                                          │·····
        gan = WGAN(args)                                                                                        │·····
      File "WGAN.py", line 130, in __init__             
    │self.data_loader = utils.load_celebA('data/celebA', transform=transforms.Compose(                       
    │AttributeError: module 'utils' has no attribute 'load_celebA'  
    
    opened by connellybarnes 1
  • gradient penalty in WGAN_GP

    gradient penalty in WGAN_GP

    Thanks for your great work! I have a question about the gradient penalty part in WGAN_GP model. From line 189 to line 194, I know that these codes compute the gradients of the pred_hat with respect to x_hat, but I don't know why you add [0] in the end. Would you please do some explanations to that? Thank you very much!

    opened by CuthbertCai 0
  • InfoGAN can not run because of the pytorch version problem

    InfoGAN can not run because of the pytorch version problem

    /home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/nn/functional.py:1806: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.") Traceback (most recent call last): File "main.py", line 112, in main() File "main.py", line 104, in main gan.train() File "/data/yangkaixing/Generative_Model_Collections/infoGAN.py", line 230, in train info_loss.backward() File "/home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/_tensor.py", line 307, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs) File "/home/yangkaixing/miniconda3/envs/GASDA/lib/python3.6/site-packages/torch/autograd/init.py", line 156, in backward allow_unreachable=True, accumulate_grad=True) # allow_unreachable flag RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [64, 3, 4, 4]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

    opened by Yang-Kaixing 0
  • RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

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

    When I run your CGAN program ,the following error message has occured: D:\ProgramData\Anaconda3\python.exe I:/gupaocode/pytorch-generative-model-collections-master/main.py --dataset mnist --gan_type CGAN --epoch 50 --batch_size 64 Traceback (most recent call last): File "I:/gupaocode/pytorch-generative-model-collections-master/main.py", line 111, in main() File "I:/gupaocode/pytorch-generative-model-collections-master/main.py", line 82, in main gan = CGAN(args) File "I:\gupaocode\pytorch-generative-model-collections-master\CGAN.py", line 94, in init data = self.data_loader.iter().next()[0] File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 517, in next data = self._next_data() File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 557, in _next_data data = self.dataset_fetcher.fetch(index) # may raise StopIteration File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\datasets\mnist.py", line 106, in getitem img = self.transform(img) File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 60, in call img = t(img) File "D:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 889, in call_impl result = self.forward(*input, **kwargs) File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\transforms.py", line 221, in forward return F.normalize(tensor, self.mean, self.std, self.inplace) File "D:\ProgramData\Anaconda3\lib\site-packages\torchvision\transforms\functional.py", line 336, in normalize tensor.sub(mean).div(std) RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

    opened by abcxq 1
  • [bug report] wrong implementation of gradient clip in WGAN?

    [bug report] wrong implementation of gradient clip in WGAN?

    Dear author,

    Thanks for your friendly implementation of popular GANs. I am reading your implementation of Wasserstein GANs, and notice that the gradient clip operation is placed after optimizer.step as seen in this line. Typically, in pytorch, the gradient operation is placed before the optimizer step.

    pls have a check.

    opened by lihuiknight 1
  • How to trian with multiple gpu?

    How to trian with multiple gpu?

    Hello @znxlwm,

    I have noticed that the GAN models are all defined with model.cuda() that use only one device. Is there any way to train them with multiple gpus so that the input size can be increased without decreasing teh batch size? Thank you.

    opened by nuanv 0
Owner
Hyeonwoo Kang
Hyeonwoo Kang
Minimal PyTorch implementation of Generative Latent Optimization from the paper "Optimizing the Latent Space of Generative Networks"

Minimal PyTorch implementation of Generative Latent Optimization This is a reimplementation of the paper Piotr Bojanowski, Armand Joulin, David Lopez-

Thomas Neumann 117 Nov 27, 2022
A PaddlePaddle version of Neural Renderer, refer to its PyTorch version

Neural 3D Mesh Renderer in PadddlePaddle A PaddlePaddle version of Neural Renderer, refer to its PyTorch version Install Run: pip install neural-rende

AgentMaker 13 Jul 12, 2022
Generative Exploration and Exploitation - This is an improved version of GENE.

GENE This is an improved version of GENE. In the original version, the states are generated from the decoder of VAE. We have to check whether the gere

null 33 Mar 23, 2022
Catch-all collection of generative art made using processing

Generative art with Processing.py Some art I have created for fun. Dependencies Processing for Python, see how to download/use here Packages contained

null 2 Mar 12, 2022
Collection of TensorFlow2 implementations of Generative Adversarial Network varieties presented in research papers.

TensorFlow2-GAN Collection of tf2.0 implementations of Generative Adversarial Network varieties presented in research papers. Model architectures will

null 41 Apr 28, 2022
MMGeneration is a powerful toolkit for generative models, based on PyTorch and MMCV.

Documentation: https://mmgeneration.readthedocs.io/ Introduction English | 简体中文 MMGeneration is a powerful toolkit for generative models, especially f

OpenMMLab 1.3k Dec 29, 2022
Pytorch implementation of Generative Models as Distributions of Functions 🌿

Generative Models as Distributions of Functions This repo contains code to reproduce all experiments in Generative Models as Distributions of Function

Emilien Dupont 117 Dec 29, 2022
Official Pytorch implementation of paper "Reverse Engineering of Generative Models: Inferring Model Hyperparameters from Generated Images"

Reverse_Engineering_GMs Official Pytorch implementation of paper "Reverse Engineering of Generative Models: Inferring Model Hyperparameters from Gener

null 100 Dec 18, 2022
A method that utilized Generative Adversarial Network (GAN) to interpret the black-box deep image classifier models by PyTorch.

A method that utilized Generative Adversarial Network (GAN) to interpret the black-box deep image classifier models by PyTorch.

Yunxia Zhao 3 Dec 29, 2022
A collection of SOTA Image Classification Models in PyTorch

A collection of SOTA Image Classification Models in PyTorch

sithu3 85 Dec 30, 2022
Deep generative modeling for time-stamped heterogeneous data, enabling high-fidelity models for a large variety of spatio-temporal domains.

Neural Spatio-Temporal Point Processes [arxiv] Ricky T. Q. Chen, Brandon Amos, Maximilian Nickel Abstract. We propose a new class of parameterizations

Facebook Research 75 Dec 19, 2022
Bayesian Image Reconstruction using Deep Generative Models

Bayesian Image Reconstruction using Deep Generative Models R. Marinescu, D. Moyer, P. Golland For technical inquiries, please create a Github issue. F

Razvan Valentin Marinescu 51 Nov 23, 2022
Generative Models for Graph-Based Protein Design

Graph-Based Protein Design This repo contains code for Generative Models for Graph-Based Protein Design by John Ingraham, Vikas Garg, Regina Barzilay

John Ingraham 159 Dec 15, 2022
Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology

Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology Sharon Zhou, Eric Zelikman

Stanford Machine Learning Group 34 Nov 16, 2022
Finding an Unsupervised Image Segmenter in each of your Deep Generative Models

Finding an Unsupervised Image Segmenter in each of your Deep Generative Models Description Recent research has shown that numerous human-interpretable

Luke Melas-Kyriazi 61 Oct 17, 2022
PULSE: Self-Supervised Photo Upsampling via Latent Space Exploration of Generative Models

PULSE: Self-Supervised Photo Upsampling via Latent Space Exploration of Generative Models Code accompanying CVPR'20 paper of the same title. Paper lin

Alex Damian 7k Dec 30, 2022
source code for https://arxiv.org/abs/2005.11248 "Accelerating Antimicrobial Discovery with Controllable Deep Generative Models and Molecular Dynamics"

Accelerating Antimicrobial Discovery with Controllable Deep Generative Models and Molecular Dynamics This work will be published in Nature Biomedical

International Business Machines 71 Nov 15, 2022