Generative Model with Dynamic Linear Flow

May 9, 2019

 

DLF – A New Family of FLOW-based Generative Model 

Abstract

Flow-based generative models are a family of exact log-likelihood models with tractable sampling and latent-variable inference, hence conceptually attractive for modeling complex distributions. However, flow-based models are limited by den- sity estimation performance issues as compared to state-of-the-art autoregressive models. Autoregressive models, which also belong to the family of likelihood- based methods, however suffer from limited parallelizability. In this paper, we propose Dynamic Linear Flow (DLF), a new family of invertible transformations with partially autoregressive structure. Our method benefits from the efficient computation of flow-based methods and high density estimation performance of autoregressive methods. We demonstrate that the proposed DLF yields state-of-the- art performance on ImageNet 32×32 and 64×64 out of all flow-based methods, and is competitive with the best autoregressive model. Additionally, our model converges 10 times faster than Glow (Kingma and Dhariwal, 2018). 

Github Link

The code is available at https://github.com/naturomics/DLF

The DLF Architecture

 

A Few Samples of the generated images

 

Figure1: Random samples from CelebA-HQ 256×256 (right, temperature 0.6), both on 8-bits.

 

Figure 2: Random samples from ImageNet 64×64 (left, temperature 1.0) 

 

Figure 3: Linear interpolation in latent space between two real images. The images have never been seen by model during training.

Technical Requirements

  • TensorFlow (tested with v1.12)

Setup

  1. Install requirements
  2. Clone this repo or click the Download ZIP button on upper right corner
  1. Download Datasets

All datasets are saved to folder data/{dataset_name} as default. If your datasets are saved at a different folder, please specify it via --data_dir command line or change the default value in main.py file to point to the right folder.

  • MNIST and CIFAR10 will be directly downloaded by the code.
  • The preprocessed and downsampled ImageNet dataset can be downloaded from https://storage.googleapis.com/glow-demo/data/imagenet-oord-tfr.tar, 32x32 and 64x64 version included. Extract and move files to the corresponding folder (r05 in the filename refers to resolution 2**5=32):
  • The preprocessed CelebA 256x256 is from https://storage.googleapis.com/glow-demo/data/celeba-tfr.tar. Extract it to folder data/celeba, for example:

If you are interested, see the scripts here to learn how these tfrecord files were generated.

 

Train the model

Outputs during training (train loss, validation loss, samples and model checkpoints) are saved to folder specified by --results_dir. Using --num_gpus for multiple GPUs training. Run python main.py -h for more helps.

Possibilities for Linear Transformation:

  • CIFAR 10 with K=2, non-inverse dynamic linear transformation
  • CIFAR 10 with K=2, inverse dynamic linear transformation
  • CIFAR 10 with K=4 and 6, non-inverse dynamic linear transformation
  • ImageNet 32x32
  • ImageNet 64x64
  • MNIST
  • CelebA-HQ 256x256

Train with your own dataset

We use tf.data API for data reading pipeline and we have written a script to standardize the code. To train with your own dataset, all you need to do is writing the tfrecords maker and the corresponding parse function, and import it in file datasets/__init__.py. See datasets/cifar10.py, datasets/mnist.py etc. for examples. When training, specify your dataset by --problem {dataset_name} command line, where dataset_name is your script name.

We will write a more detailed tutorial soon.