All Projects → aleju → gan-error-avoidance

aleju / gan-error-avoidance

Licence: GPL-3.0 license
Learning to Avoid Errors in GANs by Input Space Manipulation (Code for paper)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to gan-error-avoidance

Pytorch Mnist Celeba Cgan Cdcgan
Pytorch implementation of conditional Generative Adversarial Networks (cGAN) and conditional Deep Convolutional Generative Adversarial Networks (cDCGAN) for MNIST dataset
Stars: ✭ 290 (+1160.87%)
Mutual labels:  generative-adversarial-network, celeba
DCGAN-Pytorch
A Pytorch implementation of "Deep Convolutional Generative Adversarial Networks"
Stars: ✭ 23 (+0%)
Mutual labels:  generative-adversarial-network, celeba
Pytorch Mnist Celeba Gan Dcgan
Pytorch implementation of Generative Adversarial Networks (GAN) and Deep Convolutional Generative Adversarial Networks (DCGAN) for MNIST and CelebA datasets
Stars: ✭ 363 (+1478.26%)
Mutual labels:  generative-adversarial-network, celeba
Alae
[CVPR2020] Adversarial Latent Autoencoders
Stars: ✭ 3,178 (+13717.39%)
Mutual labels:  generative-adversarial-network, celeba
Celebamask Hq
A large-scale face dataset for face parsing, recognition, generation and editing.
Stars: ✭ 1,156 (+4926.09%)
Mutual labels:  generative-adversarial-network, celeba
cDCGAN
PyTorch implementation of Conditional Deep Convolutional Generative Adversarial Networks (cDCGAN)
Stars: ✭ 49 (+113.04%)
Mutual labels:  celeba
GraphCNN-GAN
Graph-convolutional GAN for point cloud generation. Code from ICLR 2019 paper Learning Localized Generative Models for 3D Point Clouds via Graph Convolution
Stars: ✭ 50 (+117.39%)
Mutual labels:  generative-adversarial-network
ganbert
Enhancing the BERT training with Semi-supervised Generative Adversarial Networks
Stars: ✭ 205 (+791.3%)
Mutual labels:  generative-adversarial-network
gan deeplearning4j
Automatic feature engineering using Generative Adversarial Networks using Deeplearning4j and Apache Spark.
Stars: ✭ 19 (-17.39%)
Mutual labels:  generative-adversarial-network
AGD
[ICML2020] "AutoGAN-Distiller: Searching to Compress Generative Adversarial Networks" by Yonggan Fu, Wuyang Chen, Haotao Wang, Haoran Li, Yingyan Lin, Zhangyang Wang
Stars: ✭ 98 (+326.09%)
Mutual labels:  generative-adversarial-network
adversarial-networks
Material de la charla "The bad guys in AI - atacando sistemas de machine learning"
Stars: ✭ 15 (-34.78%)
Mutual labels:  generative-adversarial-network
SDGym
Benchmarking synthetic data generation methods.
Stars: ✭ 177 (+669.57%)
Mutual labels:  generative-adversarial-network
Inventory Kamera
Scans Genshin Impact characters, artifacts, and weapons from the game window into a JSON file.
Stars: ✭ 348 (+1413.04%)
Mutual labels:  artifacts
DeepEcho
Synthetic Data Generation for mixed-type, multivariate time series.
Stars: ✭ 44 (+91.3%)
Mutual labels:  generative-adversarial-network
Cross-Domain-Image-Translation-Using-CycleGAN
CycleGAN based neural network architecture to change the gender of a person’s face
Stars: ✭ 15 (-34.78%)
Mutual labels:  generative-adversarial-network
DeepSIM
Official PyTorch implementation of the paper: "DeepSIM: Image Shape Manipulation from a Single Augmented Training Sample" (ICCV 2021 Oral)
Stars: ✭ 389 (+1591.3%)
Mutual labels:  generative-adversarial-network
BPPNet-Back-Projected-Pyramid-Network
This is the official GitHub repository for ECCV 2020 Workshop paper "Single image dehazing for a variety of haze scenarios using back projected pyramid network"
Stars: ✭ 35 (+52.17%)
Mutual labels:  generative-adversarial-network
Easter-Bootcamp-2018
Designed to take you from zero experience to GANs within a week.
Stars: ✭ 24 (+4.35%)
Mutual labels:  generative-adversarial-network
simplegan
Tensorflow-based framework to ease training of generative models
Stars: ✭ 19 (-17.39%)
Mutual labels:  generative-adversarial-network
DiscoGAN-TF
Tensorflow Implementation of DiscoGAN
Stars: ✭ 57 (+147.83%)
Mutual labels:  generative-adversarial-network

About

This repository contains code for the paper (1707.00768) Learning to Avoid Errors in GANs by Manipulating Input Spaces. The basic idea of the paper is to distort the input space (i.e. the noise vectors) in a way that the image quality is improved. More intuitively, the generator is trained to understand its own weaknesses and allowed to simply evade input vectors that would result in bad quality -- though it is punished whenever it does that. The paper introduces LIS modules, which consist of residual fully connected layers and are placed at the beginning of the generator. These modules manipulate the input vectors and thereby reduce the frequency of image artifacts (especially the frequency of completely broken images). They are almost free with regards to computation/memory. Image diversity is mostly unaffected by them.

Idea

The code in this repository is based on the one from the paper "On the Effects of Batch and Weight Normalization in Generative Adversarial Networks" (see repository). The command line arguments are largely similar or the same.

Images

G-LIS with 1 LIS module, trained on CelebA (300k batches):

CelebA, 80x80, 1 LIS module

G-LIS with 3 LIS modules, trained on CelebA (300k batches). First image per group shows the image generated by G when using the original noise vector (i.e. input space). All following images show the images generated by G when using the noise vectors (i.e. input spaces) generated by the first, second or third LIS module.

CelebA, 80x80, 3 LIS modules, chains

G-LIS with 1 LIS module at 160x160, trained on CelebA (570k batches). Note that while some faces have visible visual artifacts, there are no completely broken ones (to the point where the face is hardly recognizable). When training a similar model without LIS modules, it will generate at least some broken faces. LIS modules prevent such gross errors.

CelebA, 160x160, 1 LIS module

G-LIS with 3 LIS modules, trained on 120flowers (600k batches):

120flowers, 80x80, 3 LIS modules

G-LIS with 1 LIS module, trained on 10kcats (600k batches, 3 layers instead of 4 in G and D, NN-upsampling, dropout before last layer in D):

10kcats, 64x64, 1 LIS module

Example interpolation, same model as before:

10kcats, 64x64, 1 LIS module, interpolation

G-LIS with 1 LIS module, trained on LSUN churches (500k batches):

LSUN churches, 80x80, 1 LIS module

G-LIS with 3 LIS modules (with 2 of 3 modules executed for this image), trained on CIFAR-10 (1M batches):

CIFAR-10, 32x32, 3 LIS modules

R-iterative, images showing progressive improvements per iteration (trained on CelebA, 130k batches):

R-iterative, CelebA, 80x80, 3 iterations

R-separate correcting artifacts, before/after applying the model (2.5k batches for R, spatial dropout at 10%):

R-separate, CelebA, 80x80

Training Videos

Training on CelebA at 160x160 with one LIS module. This seems to produce more errors than 80x80 with one module. The video shows faces generated from the original noise vectors (each left) and the same noise vectors after they were manipulated by the LIS module.

Training on CelebA 160x160 before after

Same training as above, but this time only the second image of each pair is shown (i.e. only with applied LIS module).

Training on CelebA 160x160 after

Similar to the previous video, but training was done on the 10kcats datasets at 64x64 with 3 LIS modules (showing the results of the last module). Note that this is not the exactly same model as for the images above. The eyes seem to have less artifacts here. This model used one more layer in G and D as well as two more LIS modules. One of these factors likely resulted in less structural artifacts. Due to aggressive cropping the training images ended up looking a bit blurry.

Training on 10kcats 160x160 after

LIS module

Basic architecture of LIS modules:

LIS modules

Dependencies

  • python2.7 (some uses of xrange in the code)
  • pytorch at commit 065c59860a8bb5a01634bb0ce9eff6647ae1f342. At some later commit (don't know exactly which one), the weight normalization modules start to raise errors due to some internal pytorch change.
  • numpy, scipy
  • imgaug (can be commented out if no augmentation is used)
  • matplotlib
  • seaborn (only required for plotting scripts)
  • scikit-learn (only required for plotting scripts)

Usage

The below commands are optimized for CelebA. Download that dataset and extract it to a directory, e.g. /path/to/datasets/celeba. Then split it into train and test:

python common/split_data.py --dataset folder --dataroot /path/to/datasets/celeba --running 1 --final 1

R-iterative

In order to train R-iterative, saving checkpoints to e.g. /path/to/checkpoints/exp01 (where exp01 is here the name of the experiment).

python r_iterative/main.py --dataset folder --dataroot /path/to/datasets/celeba --crop_size 160 --image_size 80 --code_size 256 --norm weight --lr 0.00005 --niter 300000 --save_path /path/to/checkpoints/exp01

That command trains at 80x80 resolution (--image_size) and learning rate 0.00005 (--lr) for 300,000 batches (--niter). After the initial run of G, it executes 3 iterations of R+G (--r_iterations) with lambda_R (strength of similarity constraint) of 0.9 (changeable via --lambda_r). If you have to stop the experiment for some time, you can continue it by simply appending --load_path /path/to/checkpoints/exp01 at the end of the command (do not delete --save_path). By default, a checkpoint is saved every 2000 batches (--save_interval).

In order to sample images from G+R use

python r_iterative/sample_images.py --image_size 80 --code_size 256 --norm weight --r_iterations 3 --load_path_g /path/to/checkpoints/exp01/net_archive/last_gen.pt --load_path_r /path/to/checkpoints/exp01/net_archive/last_r.pt --save_path /path/to/outputs/exp01/final_sampled_images

This loads the last G and R from experiment exp01 and saves images to directory /path/to/outputs/exp01/. Note that the various arguments (e.g. --image_size, --r_iterations, ...) must match the ones that were used during the training.

G-LIS (G with LIS modules)

Then run the training, saving checkpoints to e.g. /path/to/checkpoints/exp01 (where exp01 is here the name of the experiment).

python g_lis/main.py --dataset folder --dataroot /path/to/datasets/celeba --crop_size 160 --image_size 80 --code_size 256 --norm weight --lr 0.00002 --r_iterations 1 --niter 300000 --save_path /path/to/checkpoints/exp01

That command trains at 80x80 resolution (--image_size) and learning rate 0.00002 (--lr) for 300,000 batches (--niter). It uses 1 LIS module (--r_iterations) with lambda_R (strength of similarity constraint) of 0.9 (changeable via --lambda_r). If you have to stop the experiment for some time, you can continue it by simply appending --load_path /path/to/checkpoints/exp01 at the end of the command (do not delete --save_path). By default, a checkpoint is saved every 5000 batches (--save_interval).

In order to sample images from the trained generator use

python g_lis/sample_images.py --image_size 80 --code_size 256 --norm weight --r_iterations 1 --load_path_g /path/to/checkpoints/exp01/net_archive/last_gen.pt --save_path /path/to/outputs/exp01/sampled_images/

This loads the last generator from experiment exp01 and saves images to directory /path/to/outputs/exp01/sampled_images/. Note that the various arguments (e.g. --image_size, --r_iterations, ...) must match the ones that were used during the training. The main subdirectories in sampled_images/ that you will care about are likely sampled_images_rX, where X starts at 0 (original noise vectors) and goes up to the value of --r_iterations (noise vectors of the last LIS module).

In order to create t-SNE plots of the noise vectors before/after LIS modules use

python g_lis/sample_tsne.py --image_size 80 --code_size 256 --norm weight --r_iterations 1 --load_path_g /path/to/checkpoints/exp01/net_archive/last_gen.pt --save_path /path/to/outputs/exp01/tsne/

The plots will be saved to /path/to/outputs/exp01/tsne/. Note that this also caches the embedded vectors. Rerunning the command with the same --save_path will load the cached points instead of re-embedding them.

In order to create probability distribution plots for the noise vector components before/after LIS modules use

python g_lis/sample_density.py --image_size 80 --code_size 256 --norm weight --r_iterations 1 --load_path_g /path/to/checkpoints/exp01/net_archive/last_gen.pt --save_path /path/to/checkpoints/exp01/density/

The plots will be saved to /path/to/outputs/exp01/density/.

In order to calculate Inception Scores (requires tensorflow) use

python g_lis/calculate_inception_scores.py --dataset folder --dataroot /path/to/datasets/celeba --crop_size 160 --image_size 80 --code_size 256 --norm weight --r_iterations 3 --inception_images 50000 --load_path /path/to/checkpoints/exp01

This will produce a lot of output, run for ages and requires significant amounts of RAM. Files that contain inception scores will be written to /path/to/checkpoints/exp01.

The below commands are roughly the ones that were used to train on CIFAR-10, 102flowers and LSUN churches:

python g_lis/main.py --dataset cifar10 --dataroot /path/to/datasets/cifar-10 --crop_size 28 --image_size 32 --augment cifar10 --code_size 256 --norm weight --lr 0.00002 --r_iterations 3 --niter 1000000 --save_interval 25000 --vis_interval 1000 --nlayer 4 --nfeature 128 --lambda_r 0.9 --nb_cache_total 300000 --nb_cache_lists 5 --cache_p_drop 0.05 --save_path /path/to/checkpoints/exp-cifar #--load_path /path/to/checkpoints/exp-cifar
python g_lis/main.py --dataset folder --dataroot /path/to/datasets/102flowers --crop_size 450 --image_size 80 --augment flowers102 --code_size 256 --norm weight --lr 0.00002 --r_iterations 3 --niter 500000 --save_interval 20000 --vis_interval 5000 --nb_cache_total 30000 --nb_cache_lists 3 --cache_p_drop 0.1 --save_path /path/to/checkpoints/exp-120flowers #--load_path /path/to/checkpoints/exp-120flowers
python g_lis/main.py --dataset folder --dataroot /path/to/datasets/church_outdoor_train_80x80_square --crop_size 76 --image_size 80 --augment lsun_churches --code_size 256 --norm weight --lr 0.00002 --r_iterations 1 --niter 500000 --save_interval 20000 --vis_interval 5000 --save_path /save/to/checkpoints/exp-churches #--load_path /save/to/checkpoints/exp-churches

The directory church_outdoor_train_80x80_square contained the LSUN churches images, which were zero-padded to be squared and then resized to 80x80.

R-separate

R-separate is integrated into G-LIS. First, train a G-LIS module according to the commands listed above. Then train R-separate using

python g_lis/train_r.py --dataset folder --dataroot /path/to/datasets/celeba --crop_size 160 --image_size 80 --code_size 256 --norm weight --r_iterations 1 --lr 0.00005 --niter 2500 --spatial_dropout_r 0.1 --save_path_r /path/to/checkpoints/r-exp01 --load_path /path/to/checkpoints/exp01

This trains R-separate for 2500 batches with spatial dropout of 10%. It is trained based on a G-LIS model which's checkpoints are saved to /path/to/checkpoints/exp01. The checkpoints of R-separate are saved to /path/to/checkpoints/r-exp01.

Then sample images using

python g_lis/sample_images.py --image_size 80 --code_size 256 --norm weight --r_iterations 1 --spatial_dropout_r 0.1 --load_path_g /path/to/checkpoints/exp01/net_archive/last_gen.pt --load_path_r /path/to/checkpoints/r-exp01/net_archive/2500_r.pt --save_path /path/to/outputs/exp01/sampled_images_r/

This saves images to /path/to/outputs/exp01/sampled_images_r/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].