Home

Awesome

Deceive D: Adaptive Pseudo Augmentation for GAN Training with Limited Data (NeurIPS 2021)

teaser

This repository provides the official PyTorch implementation for the following paper:

Deceive D: Adaptive Pseudo Augmentation for GAN Training with Limited Data<br> Liming Jiang, Bo Dai, Wayne Wu and Chen Change Loy<br> In NeurIPS 2021.<br> Project Page | Paper | Poster | Slides | YouTube Demo

Abstract: Generative adversarial networks (GANs) typically require ample data for training in order to synthesize high-fidelity images. Recent studies have shown that training GANs with limited data remains formidable due to discriminator overfitting, the underlying cause that impedes the generator's convergence. This paper introduces a novel strategy called Adaptive Pseudo Augmentation (APA) to encourage healthy competition between the generator and the discriminator. As an alternative method to existing approaches that rely on standard data augmentations or model regularization, APA alleviates overfitting by employing the generator itself to augment the real data distribution with generated images, which deceives the discriminator adaptively. Extensive experiments demonstrate the effectiveness of APA in improving synthesis quality in the low-data regime. We provide a theoretical analysis to examine the convergence and rationality of our new training strategy. APA is simple and effective. It can be added seamlessly to powerful contemporary GANs, such as StyleGAN2, with negligible computational cost.

https://user-images.githubusercontent.com/27750093/141257021-4c2aa617-3274-4b82-9577-6913d19d8a20.mp4

Updates

Requirements

Inference for Generating Images

Pretrained models can be downloaded from Google Drive:

ModelDescriptionFID
afhqcat5k256x256-apa.pklAFHQ-Cat-5k (limited itself, 256x256), trained from scratch using APA4.876
ffhq5k256x256-apa.pklFFHQ-5k (~7% data, 256x256), trained from scratch using APA13.249
anime5k256x256-apa.pklAnime-5k (~2% data, 256x256), trained from scratch using APA13.089
cub12k256x256-apa.pklCUB-12k (limited itself, 256x256), trained from scratch using APA12.889
ffhq70kfull256x256-apa.pklFFHQ-70k (full data, 256x256), trained from scratch using APA3.678
ffhq5k1024x1024-apa.pklFFHQ-5k (~7% data, 1024x1024), trained from scratch using APA9.545

The downloaded models are stored as *.pkl files that can be referenced using local filenames:

# Generate images with the truncation of 0.7
python generate.py --outdir=out --trunc=0.7 --seeds=1000-1199 --network=/path/to/checkpoint/pkl

# Generate images without truncation
python generate.py --outdir=out --trunc=1 --seeds=1000-1199 --network=/path/to/checkpoint/pkl

Outputs from the above commands will be placed under out/*.png, controlled by --outdir.

Dataset Preparation

Our used datasets can be downloaded from their official pages:

DatasetsAnimal Faces-HQ Cat (AFHQ-Cat)Flickr-Faces-HQ (FFHQ)Danbooru2019 Portraits (Anime)Caltech-UCSD Birds-200-2011 (CUB)

We use dataset_tool.py to prepare the downloaded datasets (run python dataset_tool.py --help for more information). The datasets will be stored as uncompressed ZIP archives containing uncompressed PNG files. Alternatively, a folder containing images can also be used directly as a dataset, but doing so may lead to suboptimal performance.

For instance, the ZIP archive (a subset of 5k images with a resolution of 256 × 256) of a custom dataset can be created from its folder containing images:

python dataset_tool.py --source=/path/to/image/folder --dest=/path/to/archive.zip \
    --width=256 --height=256 --max-images=5000

More detailed steps can be found at stylegan2-ada-pytorch Preparing datasets.

Training New Networks

To train a new model using the proposed APA, we recommend running the following command as a starting point to achieve desirable quality in most cases:

python train.py --outdir=./experiments --gpus=8 --data=/path/to/mydataset.zip \
    --metricdata=/path/to/mydatasetfull.zip --mirror=1 \
    --cfg=auto --aug=apa --with-dataaug=true

In this example, the results are saved to a newly created directory ./experiments/<ID>-mydataset-mirror-auto8-apa-wdataaug, controlled by --outdir. The auto8 indicates the base configuration that the hyperparameters were selected automatically for training on 8 GPUs. The training exports network pickles (network-snapshot-<INT>.pkl) and example images (fakes<INT>.png) at regular intervals (controlled by --snap).

For each pickle, the training also evaluates FID (controlled by --metrics) and logs the resulting scores in metric-fid50k_full.jsonl (as well as TFEvents if TensorBoard is installed). Following stylegan2-ada, it is noteworthy that when trained with artifically limited/amplified datasets, the quality metrics (e.g., fid50k_full) should still be evaluated against the corresponding original full datasets. We add this missing feature in stylegan2-ada-pytorch with a --metricdata argument to specify a separate metric dataset, which can differ from the training dataset (specified by --data).

This training does not necessarily lead to the optimal results, which can be further customized with additional command line options:

Please refer to python train.py --help and stylegan2-ada-pytorch Training new networks for other options.

Evaluation Metrics

By default, train.py automatically computes FID for each network pickle exported during training. We recommend inspecting metric-fid50k_full.jsonl (or TensorBoard) at regular intervals to monitor the training progress.

The metrics can also be computed after the training:

python calc_metrics.py --network=/path/to/checkpoint/pkl --gpus=8 \
    --metrics=fid50k_full,is50k --metricdata=/path/to/mydatasetfull.zip --mirror=1

The command above calculates the fid50k_full and is50k metrics for a specified checkpoint pickle file (run python calc_metrics.py --help and refer to stylegan2-ada-pytorch Quality metrics for more information). Similarly, the metrics should be evaluated against the corresponding original full dataset.

Some metrics may have a high one-off cost when calculating them for the first time on a new dataset. Also note that the evaluation is done using a different random seed each time, so the results could slightly vary if the same metric is computed multiple times.

Additional Features

Please refer to stylegan2-ada-pytorch for other usage and statistics of the codebase. Differently, the training cost of applying APA solely is negligible as opposed to ADA that spends additional time for applying external augmentations (see our paper for details).

Results

Effectiveness on Various Datasets

effectonsg2

Effectiveness Given Different Data Amounts

ffhqdiffamount

Overfitting and Convergence Analysis

overfitsg2apa

Comparison with Other State-of-the-Art Solutions

compare

Higher-Resolution Examples (1024 × 1024) on FFHQ-5k (~7% data)

1024

Citation

If you find this work useful for your research, please cite our paper:

@inproceedings{jiang2021DeceiveD,
  title={{Deceive D: Adaptive Pseudo Augmentation} for {GAN} Training with Limited Data},
  author={Jiang, Liming and Dai, Bo and Wu, Wayne and Loy, Chen Change},
  booktitle={NeurIPS},
  year={2021}
}

Acknowledgments

The code is developed based on stylegan2-ada-pytorch. We appreciate the nice PyTorch implementation.

License

Copyright (c) 2021. All rights reserved.

The code is released under the NVIDIA Source Code License.