[CVPR2020] Adversarial Latent Autoencoders
Alternatives To Alae
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Tensorflow175,304327774 hours ago46October 23, 20192,140apache-2.0C++
An Open Source Machine Learning Framework for Everyone
Transformers103,018649114 hours ago91June 21, 2022746apache-2.0Python
🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
Pytorch67,5741464 hours ago23August 10, 202212,201otherPython
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Keras58,5293306 hours ago68May 13, 2022389apache-2.0Python
Deep Learning for humans
Cs Video Courses56,273
6 days ago17
List of Computer Science courses with video lectures.
22 days ago24gpl-3.0Python
Deepfakes Software For All
D2l Zh44,141
16 hours ago45March 25, 202235apache-2.0Python
Tensorflow Examples42,312
8 months ago218otherJupyter Notebook
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)
100 Days Of Ml Code40,344
3 months ago61mit
100 Days of ML Coding
14 days ago531gpl-3.0Python
DeepFaceLab is the leading software for creating deepfakes.
Alternatives To Alae
Select To Compare

Alternative Project Comparisons

[CVPR2020] Adversarial Latent Autoencoders

Stanislav PidhorskyiDonald A. Adjeroh Gianfranco Doretto

Official repository of the paper

pytorch version

Google Drive folder with models and qualitative results


Adversarial Latent Autoencoders
Stanislav Pidhorskyi, Donald Adjeroh, Gianfranco Doretto

Abstract: Autoencoder networks are unsupervised approaches aiming at combining generative and representational properties by learning simultaneously an encoder-generator map. Although studied extensively, the issues of whether they have the same generative power of GANs, or learn disentangled representations, have not been fully addressed. We introduce an autoencoder that tackles these issues jointly, which we call Adversarial Latent Autoencoder (ALAE). It is a general architecture that can leverage recent improvements on GAN training procedures. We designed two autoencoders: one based on a MLP encoder, and another based on a StyleGAN generator, which we call StyleALAE. We verify the disentanglement properties of both architectures. We show that StyleALAE can not only generate 1024x1024 face images with comparable quality of StyleGAN, but at the same resolution can also produce face reconstructions and manipulations based on real images. This makes ALAE the first autoencoder able to compare with, and go beyond the capabilities of a generator-only type of architecture.


  • Stanislav Pidhorskyi, Donald A. Adjeroh, and Gianfranco Doretto. Adversarial Latent Autoencoders. In Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR), 2020. [to appear]
 author   = {Pidhorskyi, Stanislav and Adjeroh, Donald A and Doretto, Gianfranco},
 booktitle = {Proceedings of the IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR)},
 title    = {Adversarial Latent Autoencoders},
 year     = {2020},
 note     = {[to appear]},

preprint on arXiv: 2004.04467

To run the demo

To run the demo, you will need to have a CUDA capable GPU, PyTorch >= v1.3.1 and cuda/cuDNN drivers installed. Install the required packages:

pip install -r requirements.txt

Download pre-trained models:

python training_artifacts/

Run the demo:


You can specify yaml config to use. Configs are located here: By default, it uses one for FFHQ dataset. You can change the config using -c parameter. To run on celeb-hq in 256x256 resolution, run:

python -c celeba-hq256

However, for configs other then FFHQ, you need to obtain new principal direction vectors for the attributes.

Repository organization

Running scripts

The code in the repository is organized in such a way that all scripts must be run from the root of the repository. If you use an IDE (e.g. PyCharm or Visual Studio Code), just set Working Directory to point to the root of the repository.

If you want to run from the command line, then you also need to set PYTHONPATH variable to point to the root of the repository.

For example, let's say we've cloned repository to ~/ALAE directory, then do:

$ cd ~/ALAE


Now you can run scripts as follows:

$ python style_mixing/

Repository structure

Path Description
ALAE Repository root folder
├  configs Folder with yaml config files.
│  ├  bedroom.yaml Config file for LSUN bedroom dataset at 256x256 resolution.
│  ├  celeba.yaml Config file for CelebA dataset at 128x128 resolution.
│  ├  celeba-hq256.yaml Config file for CelebA-HQ dataset at 256x256 resolution.
│  ├  celeba_ablation_nostyle.yaml Config file for CelebA 128x128 dataset for ablation study (no styles).
│  ├  celeba_ablation_separate.yaml Config file for CelebA 128x128 dataset for ablation study (separate encoder and discriminator).
│  ├  celeba_ablation_z_reg.yaml Config file for CelebA 128x128 dataset for ablation study (regress in Z space, not W).
│  ├  ffhq.yaml Config file for FFHQ dataset at 1024x1024 resolution.
│  ├  mnist.yaml Config file for MNIST dataset using Style architecture.
│  └  mnist_fc.yaml Config file for MNIST dataset using only fully connected layers (Permutation Invariant MNIST).
├  dataset_preparation Folder with scripts for dataset preparation.
│  ├ To prepare TFRecords for CelebA-HQ dataset at 256x256 resolution.
│  ├ To prepare TFRecords for CelebA dataset at 128x128 resolution.
│  ├ To prepare TFRecords for MNIST dataset.
│  ├ To split official TFRecords from StyleGAN paper for LSUN bedroom dataset.
│  └ To split official TFRecords from StyleGAN paper for FFHQ dataset.
├  dataset_samples Folder with sample inputs for different datasets. Used for figures and for test inputs during training.
├  make_figures Scripts for making various figures.
├  metrics Scripts for computing metrics.
├  principal_directions Scripts for computing principal direction vectors for various attributes. For interactive demo.
├  style_mixing Sample inputs and script for producing style-mixing figures.
├  training_artifacts Default place for saving checkpoints/sample outputs/plots.
│  └ Script for downloading all pretrained models.
├ Runnable script for interactive demo.
├ Runnable script for training.
├ Runnable script for training for ablation study (separate encoder and discriminator).
├ Module for saving/restoring model weights, optimizer state and loss history.
├ Customized adam optimizer for learning rate equalization and zero second beta.
├ Module with dataset classes, loaders, iterators, etc.
├ Definition for config variables with default values.
├ Helper for running multi-GPU, multiprocess training. Sets up config and logging.
├ Helper class for managing growing/stabilizing network.
├ Custom Linear, Conv2d and ConvTranspose2d modules for learning rate equalization.
├ Module with high-level model definition.
├ Same as above, but for ablation study.
├ Definition of all network blocks for multiple architectures.
├ Registry of network blocks for selecting from config file.
├ Custom schedulers with warm start and aggregating several optimizers.
├ Module for plotting losses.
└ Decorator for async call, decorator for caching, registry for network blocks.


In this codebase yacs is used to handle configurations.

Most of the runnable scripts accept -c parameter that can specify config files to use. For example, to make reconstruction figures, you can run:

python make_figures/
python make_figures/ -c celeba
python make_figures/ -c celeba-hq256
python make_figures/ -c bedroom

The Default config is ffhq.


Training is done using TFRecords. TFRecords are read using DareBlopy, which allows using them with Pytorch.

In config files as well as in all preparation scripts, it is assumed that all datasets are in /data/datasets/. You can either change path in config files, either create a symlink to where you store datasets.

The official way of generating CelebA-HQ can be challenging. Please refer to this page: suvojit-0x55aa/celebA-HQ-dataset-download You can get the pre-generated dataset from:

Pre-trained models

To download pre-trained models run:

python training_artifacts/

Note: There used to be problems with downloading models from Google Drive due to download limit. Now, the script is setup in a such way that if it fails to download data from Google Drive it will try to download it from S3.

If you experience problems, try deleting all *.pth files, updating dlutils package (pip install dlutils --upgrade) and then run again. If that does not solve the problem, please open an issue. Also, you can try downloading models manually from here:

In config files, OUTPUT_DIR points to where weights are saved to and read from. For example: OUTPUT_DIR: training_artifacts/celeba-hq256

In OUTPUT_DIR it saves a file last_checkpoint which contains path to the actual .pth pickle with model weight. If you want to test the model with a specific weight file, you can simply modify last_checkpoint file.

Generating figures


To generate style-mixing figures run:

python style_mixing/ -c <config>

Where instead of <config> put one of: ffhq, celeba, celeba-hq256, bedroom


To generate reconstruction with multiple scale images:

python make_figures/ -c <config>

To generate reconstruction from all sample inputs on multiple pages:

python make_figures/ -c <config>

There are also:

python make_figures/old/
python make_figures/old/

To generate reconstruction from test set of FFHQ:

python make_figures/

To generate interpolation figure:

python make_figures/ -c <config>

To generate traversals figure:

(For datasets other then FFHQ, you will need to find principal directions first)

python make_figures/ -c <config>


To make generation figure run: -c <config>


In addition to installing required packages:

pip install -r requirements.txt

You will need to install DareBlopy:

pip install dareblopy

To run training:

python -c <config>

It will run multi-GPU training on all available GPUs. It uses DistributedDataParallel for parallelism. If only one GPU available, it will run on single GPU, no special care is needed.

The recommended number of GPUs is 8. Reproducibility on a smaller number of GPUs may have issues. You might need to adjust the batch size in the config file depending on the memory size of the GPUs.

Running metrics

In addition to installing required packages and DareBlopy, you need to install TensorFlow and dnnlib from StyleGAN.

Tensorflow must be of version 1.10:

pip install tensorflow-gpu==1.10

It requires CUDA version 9.0.

Perhaps, the best way is to use Anaconda to handle this, but I prefer installing CUDA 9.0 from pop-os repositories (works on Ubuntu):

sudo echo "deb bionic main" | sudo tee -a /etc/apt/sources.list.d/pop-proprietary.list
sudo apt-key adv --keyserver --recv-key 204DD8AEC33A7AFF
sudo apt update

sudo apt install system76-cuda-9.0
sudo apt install system76-cudnn-9.0

Then just set LD_LIBRARY_PATH variable:

export LD_LIBRARY_PATH=/usr/lib/cuda-9.0/lib64

Dnnlib is a package used in StyleGAN. You can install it with:

pip install

All code for running metrics is heavily based on those from StyleGAN repository. It also uses the same pre-trained models:


inception_v3_features.pkl and inception_v3_softmax.pkl are derived from the pre-trained Inception-v3 network by Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jonathon Shlens, and Zbigniew Wojna. The network was originally shared under Apache 2.0 license on the TensorFlow Models repository.

vgg16.pkl and vgg16_zhang_perceptual.pkl are derived from the pre-trained VGG-16 network by Karen Simonyan and Andrew Zisserman. The network was originally shared under Creative Commons BY 4.0 license on the Very Deep Convolutional Networks for Large-Scale Visual Recognition project page.

vgg16_zhang_perceptual.pkl is further derived from the pre-trained LPIPS weights by Richard Zhang, Phillip Isola, Alexei A. Efros, Eli Shechtman, and Oliver Wang. The weights were originally shared under BSD 2-Clause "Simplified" License on the PerceptualSimilarity repository.

Finally, to run metrics:

python metrics/ -c <config>       # FID score on generations
python metrics/ -c <config>   # FID score on reconstructions
python metrics/ -c <config>       # PPL score on generations
python metrics/ -c <config>     # LPIPS score of reconstructions
Popular Machine Learning Projects
Popular Deep Learning Projects
Popular Machine Learning Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Machine Learning
Deep Learning
Neural Network
Computer Vision
Generative Adversarial Network
Generative Model