2018-05-04 22:11:26 +03:00
< p align = "center" >
2018-05-04 22:32:41 +03:00
< img src = "assets/keras_gan.png" width = "480" \>
2018-05-04 22:11:26 +03:00
< / p >
2017-07-11 19:44:22 +03:00
2018-05-04 22:55:12 +03:00
## Keras-GAN
Collection of Keras implementations of Generative Adversarial Networks (GANs) suggested in research papers. These models are in some cases simplified versions of the ones ultimately described in the papers, but I have chosen to focus on getting the core ideas covered instead of getting every layer configuration right. Contributions and suggestions of GAN varieties to implement are very welcomed.
2017-07-11 19:44:22 +03:00
2018-05-04 19:41:41 +03:00
< b > See also:</ b > [PyTorch-GAN ](https://github.com/eriklindernoren/PyTorch-GAN )
2018-04-22 15:05:22 +03:00
2017-07-14 23:17:48 +03:00
## Table of Contents
2018-02-14 03:09:54 +03:00
* [Installation ](#installation )
2017-07-14 23:17:48 +03:00
* [Implementations ](#implementations )
+ [Auxiliary Classifier GAN ](#ac-gan )
2017-07-16 19:30:29 +03:00
+ [Adversarial Autoencoder ](#adversarial-autoencoder )
2017-07-18 02:43:52 +03:00
+ [Bidirectional GAN ](#bigan )
2018-01-22 17:49:13 +03:00
+ [Boundary-Seeking GAN ](#bgan )
2018-02-27 15:59:31 +03:00
+ [Conditional GAN ](#cgan )
2017-07-16 12:15:31 +03:00
+ [Context-Conditional GAN ](#cc-gan )
2017-07-16 16:38:13 +03:00
+ [Context Encoder ](#context-encoder )
2018-01-22 18:30:53 +03:00
+ [Coupled GANs ](#cogan )
2018-02-14 01:40:17 +03:00
+ [CycleGAN ](#cyclegan )
2017-07-14 23:17:48 +03:00
+ [Deep Convolutional GAN ](#dcgan )
2018-03-14 22:20:08 +03:00
+ [DiscoGAN ](#discogan )
2018-01-22 23:00:11 +03:00
+ [DualGAN ](#dualgan )
2017-07-14 23:17:48 +03:00
+ [Generative Adversarial Network ](#gan )
2017-07-19 01:59:12 +03:00
+ [InfoGAN ](#infogan )
2018-01-22 17:22:55 +03:00
+ [LSGAN ](#lsgan )
2018-02-27 17:50:12 +03:00
+ [Pix2Pix ](#pix2pix )
2018-04-07 19:24:40 +03:00
+ [PixelDA ](#pixelda )
2017-07-14 23:17:48 +03:00
+ [Semi-Supervised GAN ](#sgan )
2018-03-01 03:17:43 +03:00
+ [Super-Resolution GAN ](#srgan )
2017-07-14 23:17:48 +03:00
+ [Wasserstein GAN ](#wgan )
2018-05-11 20:56:34 +03:00
+ [Wasserstein GAN GP ](#wgan-gp )
2018-01-22 17:22:55 +03:00
2018-02-14 03:09:54 +03:00
## Installation
$ git clone https://github.com/eriklindernoren/Keras-GAN
2018-04-10 10:02:53 +03:00
$ cd Keras-GAN/
2018-02-14 03:09:54 +03:00
$ sudo pip3 install -r requirements.txt
2017-07-14 23:19:48 +03:00
2017-07-14 23:17:48 +03:00
## Implementations
2017-07-16 12:15:31 +03:00
### AC-GAN
2018-04-10 10:18:52 +03:00
Implementation of _Auxiliary Classifier Generative Adversarial Network_ .
2017-07-11 19:44:22 +03:00
2017-07-18 22:04:59 +03:00
[Code ](acgan/acgan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1610.09585
2017-07-11 19:44:22 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd acgan/
$ python3 acgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-16 19:31:56 +03:00
< p align = "center" >
2018-03-01 13:51:28 +03:00
< img src = "http://eriklindernoren.se/images/acgan.gif" width = "640" \>
2017-07-16 19:31:56 +03:00
< / p >
2017-07-16 19:30:29 +03:00
### Adversarial Autoencoder
2018-04-10 10:18:52 +03:00
Implementation of _Adversarial Autoencoder_ .
2017-07-16 19:30:29 +03:00
2018-05-14 13:39:31 +03:00
[Code ](aae/aae.py )
2017-07-16 19:30:29 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1511.05644
2017-07-16 19:30:29 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd aae/
$ python3 aae.py
2018-04-10 09:56:45 +03:00
```
2017-07-11 19:44:22 +03:00
< p align = "center" >
2017-07-16 19:30:29 +03:00
< img src = "http://eriklindernoren.se/images/aae.png" width = "640" \>
2017-07-11 19:44:22 +03:00
< / p >
2017-07-16 12:15:31 +03:00
2017-07-18 02:43:52 +03:00
### BiGAN
2018-04-10 10:18:52 +03:00
Implementation of _Bidirectional Generative Adversarial Network_ .
2017-07-18 02:43:52 +03:00
2017-07-18 22:04:59 +03:00
[Code ](bigan/bigan.py )
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1605.09782
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd bigan/
$ python3 bigan.py
2018-04-10 09:56:45 +03:00
```
2018-01-22 17:49:13 +03:00
### BGAN
2018-04-10 10:18:52 +03:00
Implementation of _Boundary-Seeking Generative Adversarial Networks_ .
2018-01-22 17:49:13 +03:00
[Code ](bgan/bgan.py )
Paper: https://arxiv.org/abs/1702.08431
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd bgan/
$ python3 bgan.py
2018-04-10 09:56:45 +03:00
```
2018-02-18 16:55:41 +03:00
### CC-GAN
2018-04-10 10:18:52 +03:00
Implementation of _Semi-Supervised Learning with Context-Conditional Generative Adversarial Networks_ .
2017-07-16 12:15:31 +03:00
2017-07-18 22:04:59 +03:00
[Code ](ccgan/ccgan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1611.06430
2017-07-16 12:15:31 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd ccgan/
$ python3 ccgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-11 19:44:22 +03:00
< p align = "center" >
2017-07-16 12:15:31 +03:00
< img src = "http://eriklindernoren.se/images/ccgan.png" width = "640" \>
2017-07-11 19:44:22 +03:00
< / p >
2018-02-27 15:58:44 +03:00
### CGAN
2018-04-10 10:18:52 +03:00
Implementation of _Conditional Generative Adversarial Nets_ .
2018-02-27 15:58:44 +03:00
[Code ](cgan/cgan.py )
Paper:https://arxiv.org/abs/1411.1784
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd cgan/
$ python3 cgan.py
2018-04-10 09:56:45 +03:00
```
2018-02-27 15:58:44 +03:00
< p align = "center" >
2018-02-27 16:20:58 +03:00
< img src = "http://eriklindernoren.se/images/cgan.gif" width = "640" \>
2018-02-27 15:58:44 +03:00
< / p >
2017-07-16 16:38:13 +03:00
### Context Encoder
2018-04-10 10:18:52 +03:00
Implementation of _Context Encoders: Feature Learning by Inpainting_ .
2017-07-16 16:38:13 +03:00
2017-07-18 22:04:59 +03:00
[Code ](context_encoder/context_encoder.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1604.07379
2017-07-16 16:38:13 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd context_encoder/
$ python3 context_encoder.py
2018-04-10 09:56:45 +03:00
```
2017-07-16 16:38:13 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/context_encoder.png" width = "640" \>
< / p >
2018-01-22 18:30:53 +03:00
### CoGAN
2018-04-10 10:18:52 +03:00
Implementation of _Coupled generative adversarial networks_ .
2018-01-22 18:30:53 +03:00
[Code ](cogan/cogan.py )
Paper: https://arxiv.org/abs/1606.07536
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd cogan/
$ python3 cogan.py
2018-04-10 09:56:45 +03:00
```
2018-02-14 01:40:17 +03:00
### CycleGAN
2018-04-10 10:18:52 +03:00
Implementation of _Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks_ .
2018-02-14 01:40:17 +03:00
[Code ](cyclegan/cyclegan.py )
Paper: https://arxiv.org/abs/1703.10593
2018-02-14 01:50:21 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/cyclegan.png" width = "640" \>
< / p >
2018-04-10 10:06:49 +03:00
#### Example
2018-02-18 16:55:41 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd cyclegan/
2018-02-18 16:55:41 +03:00
$ bash download_dataset.sh apple2orange
$ python3 cyclegan.py
2018-02-18 19:13:31 +03:00
```
2018-02-18 16:55:41 +03:00
< p align = "center" >
2018-02-18 19:13:31 +03:00
< img src = "http://eriklindernoren.se/images/cyclegan_gif.gif" width = "640" \>
2018-02-18 16:55:41 +03:00
< / p >
2017-07-11 19:44:22 +03:00
### DCGAN
2018-04-10 10:18:52 +03:00
Implementation of _Deep Convolutional Generative Adversarial Network_ .
2017-07-11 19:44:22 +03:00
2017-07-18 22:04:59 +03:00
[Code ](dcgan/dcgan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1511.06434
2017-07-11 20:46:31 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd dcgan/
$ python3 dcgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-11 20:46:31 +03:00
< p align = "center" >
2017-07-13 23:22:37 +03:00
< img src = "http://eriklindernoren.se/images/dcgan2.png" width = "640" \>
2017-07-11 20:46:31 +03:00
< / p >
2017-07-13 00:22:09 +03:00
2018-03-14 22:20:08 +03:00
### DiscoGAN
2018-04-10 10:18:52 +03:00
Implementation of _Learning to Discover Cross-Domain Relations with Generative Adversarial Networks_ .
2018-03-14 22:20:08 +03:00
[Code ](discogan/discogan.py )
Paper: https://arxiv.org/abs/1703.05192
< p align = "center" >
< img src = "http://eriklindernoren.se/images/discogan_architecture.png" width = "640" \>
< / p >
2018-04-10 10:06:49 +03:00
#### Example
2018-03-14 22:20:08 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd discogan/
2018-03-14 22:57:35 +03:00
$ bash download_dataset.sh edges2shoes
2018-03-14 22:20:08 +03:00
$ python3 discogan.py
```
2018-03-15 15:43:53 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/discogan.png" width = "640" \>
< / p >
2018-01-22 23:01:14 +03:00
### DualGAN
2018-04-10 10:18:52 +03:00
Implementation of _DualGAN: Unsupervised Dual Learning for Image-to-Image Translation_ .
2018-01-22 23:00:11 +03:00
[Code ](dualgan/dualgan.py )
Paper: https://arxiv.org/abs/1704.02510
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd dualgan/
$ python3 dualgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-14 23:17:48 +03:00
### GAN
2018-04-10 10:18:52 +03:00
Implementation of _Generative Adversarial Network_ with a MLP generator and discriminator.
2017-07-14 23:17:48 +03:00
2017-07-18 22:04:59 +03:00
[Code ](gan/gan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1406.2661
2017-07-14 23:17:48 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd gan/
$ python3 gan.py
2018-04-10 09:56:45 +03:00
```
2017-07-14 23:17:48 +03:00
< p align = "center" >
2018-04-12 10:12:52 +03:00
< img src = "http://eriklindernoren.se/images/gan_mnist5.gif" width = "640" \>
2017-07-14 23:17:48 +03:00
< / p >
2017-07-19 01:59:12 +03:00
### InfoGAN
2018-04-10 10:18:52 +03:00
Implementation of _InfoGAN: Interpretable Representation Learning by Information Maximizing Generative Adversarial Nets_ .
2017-07-19 01:59:12 +03:00
[Code ](infogan/infogan.py )
Paper: https://arxiv.org/abs/1606.03657
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd infogan/
$ python3 infogan.py
2018-04-10 09:56:45 +03:00
```
2018-01-22 01:45:49 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/infogan.png" width = "640" \>
< / p >
2018-01-22 17:22:55 +03:00
### LSGAN
2018-04-10 10:18:52 +03:00
Implementation of _Least Squares Generative Adversarial Networks_ .
2018-01-22 17:22:55 +03:00
[Code ](lsgan/lsgan.py )
Paper: https://arxiv.org/abs/1611.04076
2017-07-19 01:59:12 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd lsgan/
$ python3 lsgan.py
2018-04-10 09:56:45 +03:00
```
2018-02-27 17:50:12 +03:00
### Pix2Pix
2018-05-19 20:43:39 +03:00
Implementation of _Image-to-Image Translation with Conditional Adversarial Networks_ .
2018-02-27 17:50:12 +03:00
[Code ](pix2pix/pix2pix.py )
Paper: https://arxiv.org/abs/1611.07004
< p align = "center" >
< img src = "http://eriklindernoren.se/images/pix2pix_architecture.png" width = "640" \>
< / p >
2018-04-10 10:06:49 +03:00
#### Example
2018-02-27 17:50:12 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd pix2pix/
2018-02-27 17:50:12 +03:00
$ bash download_dataset.sh facades
$ python3 pix2pix.py
```
< p align = "center" >
2018-02-27 17:58:24 +03:00
< img src = "http://eriklindernoren.se/images/pix2pix2.png" width = "640" \>
2018-02-27 17:50:12 +03:00
< / p >
2018-04-07 19:24:40 +03:00
### PixelDA
2018-04-10 10:18:52 +03:00
Implementation of _Unsupervised Pixel-Level Domain Adaptation with Generative Adversarial Networks_ .
2018-04-07 19:24:40 +03:00
[Code ](pixelda/pixelda.py )
Paper: https://arxiv.org/abs/1612.05424
2018-04-10 10:06:49 +03:00
#### MNIST to MNIST-M Classification
2018-04-08 16:37:22 +03:00
Trains a classifier on MNIST images that are translated to resemble MNIST-M (by performing unsupervised image-to-image domain adaptation). This model is compared to the naive solution of training a classifier on MNIST and evaluating it on MNIST-M. The naive model manages a 55% classification accuracy on MNIST-M while the one trained during domain adaptation gets a 95% classification accuracy.
2018-04-07 19:24:40 +03:00
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd pixelda/
$ python3 pixelda.py
2018-04-10 09:56:45 +03:00
```
2018-04-07 19:24:40 +03:00
| Method | Accuracy |
| ------------ |:---------:|
| Naive | 55% |
| PixelDA | 95% |
2017-07-14 23:17:48 +03:00
### SGAN
2018-04-10 10:18:52 +03:00
Implementation of _Semi-Supervised Generative Adversarial Network_ .
2017-07-14 23:17:48 +03:00
2017-07-18 22:04:59 +03:00
[Code ](sgan/sgan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1606.01583
2017-07-14 23:17:48 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd sgan/
$ python3 sgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-16 12:15:31 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/sgan.png" width = "640" \>
< / p >
2018-03-01 03:17:43 +03:00
### SRGAN
2018-04-10 10:18:52 +03:00
Implementation of _Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network_ .
2018-03-01 03:17:43 +03:00
[Code ](srgan/srgan.py )
Paper: https://arxiv.org/abs/1609.04802
< p align = "center" >
2018-03-01 12:58:09 +03:00
< img src = "http://eriklindernoren.se/images/superresgan.png" width = "640" \>
2018-03-01 03:17:43 +03:00
< / p >
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd srgan/
2018-04-10 09:56:45 +03:00
< follow steps at the top of srgan . py >
2018-04-10 10:02:53 +03:00
$ python3 srgan.py
2018-04-10 09:56:45 +03:00
```
2018-03-01 03:17:43 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/srgan.png" width = "640" \>
< / p >
2017-07-13 00:22:09 +03:00
### WGAN
2018-04-10 10:18:52 +03:00
Implementation of _Wasserstein GAN_ (with DCGAN generator and discriminator).
2017-07-13 00:22:09 +03:00
2017-07-18 22:04:59 +03:00
[Code ](wgan/wgan.py )
2017-07-16 16:38:13 +03:00
2017-07-18 02:43:52 +03:00
Paper: https://arxiv.org/abs/1701.07875
2017-07-13 23:22:37 +03:00
2018-04-10 10:06:49 +03:00
#### Example
2018-04-10 09:56:45 +03:00
```
2018-04-10 10:02:53 +03:00
$ cd wgan/
$ python3 wgan.py
2018-04-10 09:56:45 +03:00
```
2017-07-13 23:22:37 +03:00
< p align = "center" >
< img src = "http://eriklindernoren.se/images/wgan2.png" width = "640" \>
< / p >
2018-05-11 20:56:34 +03:00
### WGAN GP
Implementation of _Improved Training of Wasserstein GANs_ .
[Code ](wgan_gp/wgan_gp.py )
Paper: https://arxiv.org/abs/1704.00028
#### Example
```
$ cd wgan_gp/
$ python3 wgan_gp.py
```
< p align = "center" >
< img src = "http://eriklindernoren.se/images/imp_wgan.gif" width = "640" \>
< / p >