Skip to content
Disentanglement library for PyTorch
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Update circleci Jun 5, 2019
aicrowd Semi-merge the two dataloaders Nov 1, 2019
architectures Fix dset_dir bug Jul 19, 2019
common Add support for beta_vae_sklearn Nov 9, 2019
extra_metrics_configs Initial crowdai commit Jul 16, 2019
models Update arguments' names Nov 9, 2019
scripts Update arguments' names Nov 9, 2019
.gitattributes Add dsprite_CVAE saved results Nov 6, 2019
LICENSE Initial commit May 31, 2019 Update Dec 12, 2019
aicrowd.json Initial crowdai commit Jul 16, 2019
apt.txt Initial crowdai commit Jul 16, 2019
environment.yml Revert environmen.yml Sep 20, 2019 Refactor Nov 26, 2019
requirements.txt Merge pull request #7 from amir-abdi/dependabot/pip/werkzeug-0.16.0 Oct 30, 2019 update Nov 1, 2019
runtime.txt Initial crowdai commit Jul 16, 2019 Debug Nov 6, 2019



Pytorch Implementation of Disentanglement algorithms for Variational Autoencoders. This library was developed as a contribution to the Disentanglement Challenge of NeurIPS 2019.

If the library helped your research, consider citing the corresponding submission of the NeurIPS 2019 Disentanglement Challenge:

    Author = {Amir H. Abdi and Purang Abolmaesumi and Sidney Fels},
    Title = {Variational Learning with Disentanglement-PyTorch},
    Year = {2019},
    journal={arXiv preprint arXiv:1912.05184},    

The following algorithms are implemented:

Note: Everything is modular, you can mix and match neural architectures and algorithms. Also, multiple loss terms can be included in the --loss_terms argument, each with their respective weights. This enables us to combine a set of disentanglement algorithms for representation learning.

Requirements and Installation

Install the requirements: pip install -r requirements.txt
Or build conda environment: conda env create -f environment.yml

The library visualizes the reconstructed images and the traversed latent spaces and saves them as static frames as well as animated GIFs. It also extensively uses the web-based Weights & Biases toolkit for logging and visualization purposes.


python [[--ARG ARG_VALUE] ...]


bash scripts/SCRIPT_NAME

Flags and Configs

  • --alg: The main formulation for training.
    Values: AE (AutoEncoder), VAE (Variational AutoEncoder), BetaVAE, CVAE (Conditional VAE), IFCVAE (Information Factorization CVAE)

  • --loss_terms: Extensions to the VAE algorithm are implemented as plug-ins to the original forumation. As a result, if the loss terms of two learning algorithms (e.g., A and B) were found to be compatible, they can simultaneously be included in the objective function with the flag set as --loss_terms A B. The loss_terms flag can be used with VAE, BetaVAE, CVAE, and IFCVAE algorithms.

  • --evaluation_metric: Metric(s) to use for disentanglement evaluation (see scripts/aicrowd_challenge).
    Values: mig, sap_score, irs, factor_vae_metric, dci, beta_vae_sklearn

For the complete list of arguments, please check the source.

Data Setup

To run the scripts:

1- Set the -dset_dir flag or the $DISENTANGLEMENT_LIB_DATA environment variable to the directory holding all the datasets (the former is given priority).

2- Set the dset_name flag or the $DATASET_NAME environment variable to the name of the dataset (the former is given priority). The supported datasets are: celebA, dsprites (and the Deppmind's variants: color, noisy, scream, introduced here), smallnorb, cars3d, mpi3d_toy, and mpi3d_realistic, and mpi3d_real.

Please check the repository for the mpi3d datasets for license agreements and consider citing their work.

Currently, there are two dataloaders in place:

  • One handles labels for semi-supervised and conditional (class-aware) training (e.g. CVAE, IFCVAE) , but only supports the celebA and dsprites_full datasets for now.
  • The other leverages Google's implementations of disentanglement_lib, and is based on the starter kit of the Disentanglement Challenge of NeurIPS 2019, hosted by AIcrowd.

NeurIPS 2019 Disentanglement Challenge

To use this code in the NeurIPS 2019 Disentanglement Challenge

  • Set --aicrowd_challenge=true in your bash file
  • Use --evaluate_metric mig sap_score irs factor_vae_metric dci to assess the progression of disentanglement metrics during training.
  • Set the last line of to your highest performing configuration.
  • Follow the instructions on this starter kit to setup your AIcrowd and gitlab credentials and keys, and push the source code to your repository on GitLab.

Sample Results

Method Latent traversal visualization
CVAE (conditioned on shape)
Right-most item is traversing the condition
IFCVAE (factorized on shape)
Right-most factor is enforced to encode the shape


Any contributions, especially around implementing more disentanglement algorithms, are welcome. Feel free to submit bugs, feature requests, or questions as issues, or contact me directly via email at:

You can’t perform that action at this time.