Code Monkey home page Code Monkey logo

representation-learning's Introduction

Representation-Learning

Representation Learning of Image Data with VAE. Alexander Piehler, Moritz Wagner

Introduction

This Github Repository is developed by Moritz Wagner and Alexander Piehler in collaboration with Adidas. This project stresses the suitability of Variational Autoencoders for representation learning of image data. The main goal was to establish a codebase that allows for reproducing and tracking experiments via mlflow. The world of Variational Autoencoders is quite large and therefore, we restricted ourselves to the ones we believed that would perform best. To further benchmark, we also included PCA and Autoencoders. The following models were considered:

├── VAE
├── beta-VAE
├── InfoVAE
├── GaussMixVAE
├── DIP-VAE
├── PCA
├── Autoencoder

For each model, we found some valid hyperparameter configurations that can be considered in the folder configs/.

Code Structure

This framework is structured as follows:

├── configs
├── data
├── experiments
├── library
├── playground

configs

Contains the config files for each model depending on the chosen data set.

data

In this folder, you find all relevant python scripts to download and preprocess the data for running the models.

experiments

Contains the scripts for running all relevant experiments. To run them in the right order, follow these steps: To run them first change into the directory accordingly: cd experiments

  1. python seed_running.py
  2. python latent_experiment.py
  3. python epochs_experiment.py
  4. python kld_weight_experiment.py
  5. python latent_experiment.py
  6. python tune_models.py
  7. python run_best_configurations.py
  8. python deep_dive.py

library

This is the package for this repository, it stores all functions and (model) classes that are used. The package contains different modules

├── models2
├── architectures.py
├── eval_helpers.py
├── evaluator.py
├── postprocessing.py
├── utils.py
├── visualizer.py
└── viz_helpers.py

playground

Contains only some playground files which are absolutely not important to consider.

Packaging

  • package libraryenables pip installation and symling creation
  • fork the repository and execute pip install -e . from the parent tree.
  • packaging allows also for updating the packages in the scripts via importlib.reload()

Setup

You can setup Representation-Learning as follows: Note, all commands must be run from parent level of the repository.

  1. Install miniconda
  2. Create a conda environmnet for python 3.7 (conda create -n <env name> python=3.7)
  3. Clone this repository
  4. Install the required packages via pip install -r requirements.txt
  5. Install the local package library as described above.
  6. Download the data by moving to data folder cd data and executing python get_<dataset>_data.py
  7. Run code from run.py --config/config_file.yaml

Further notes on running experiments.

In case that hyperparameters want to be adjusted, you can do so by respectively adjusting the parameters set in the config files. Note, however, the parameter configurations listed we found worked best for the respective problem. If you want to run your own experiments, it is advisable to additionally specify the run_name and the experiment_name. This is required for mlflow to log adequately. An exemplary command could be as follows: python run.py --configs/MNIST/vae.yaml --run_name mnist_vae --experiment_name mnist_vae

representation-learning's People

Contributors

moritzwag avatar alexpiehler avatar

Stargazers

 avatar  avatar

Watchers

Fabian Scheipl avatar  avatar  avatar  avatar

representation-learning's Issues

implement first running version of Variational Autoencoder

Build a running version of a Variational Autoencoder.
Note, that it should be modularized well.
Meaning this should work for any kind of reparameterization Trick and any type of Encoder/Decoder architecture.
Work in branch "vae_model"

Experimentation Setup

Experimental Setups

Experiment Description Models Output
Different Seeds try different seeds to evaluate stochasticity VanillaVae BoxPlot, dataframe
Epochs evaluate the influence of no. of epocs 40, 80, 120 VanilleVae traversal plots, disentaglement metrics
Latent Dimensions evaluate influence of number of latent dims 10, 20, 40 VanillaVae Active Units
ResNet as Encoder try ResNet as encoder to evaluate the influence of the architecture on the model VanillaVae Traversal Plots, disentanglement metrics

Tuning Models with Hyperband

We want to tune all models with hyperband and a fixed time budget that is equal for all models.
This gives us a better comparability.

Model Parameters Budget Done
GaussianVae None None
BetaVae beta: [low=1, high=20, steps=2]; max_capacity: [low=1, high=50, step=5] 50h 16.08 21.00h
DIPVae lambda_dig: [low=1, high=20, steps=2]; lambda_offdig: [low=1, high=30, step=2] 50h 20.8 0.00h
GaussMixVae temperature: [low=1, high=40, steps=10]; anneal_rate: [low=0.1, high=0.5, steps=0.1] cont_weight [1, 2, 3]; cat_weight = [1, 2, 3] ??? tbd
InfoVae to be discussed ??? tbd

Beta-Vae Implementation

@alexpiehler
implement beta Vae based on the following repo:
https://github.com/AntixK/PyTorch-VAE
betaVae: https://github.com/AntixK/PyTorch-VAE/blob/master/models/beta_vae.py
The code structure between their and our repository is highly comparable.
Pleas implement beta vae in file 'library/models2/beta_vae.py'
and additional add the relevant config file as 'beta_vae.yaml'

work in branch:
beta_vae

For doing this, follow these steps:
1.) git pull origin master
2.) git checkout -b beta_vae

and once your are done:

1.) git add *
2.) git commit
3.) git push origin beta_vae
4.) lastly create on github page a pull request (green button should pop-up) so that we can merge into master, once review is finished.

Fix annealing procedure of temperature in CatVae

The implementation of the catvae is still missing the annealing of the temperature parameter, which is used in the gumbel softmax function.
The problem is that we need to be able to access a attribute batch_idx from somewhere. The code is currently commented out.

#try:
# #pdb.set_trace()
# #batch_idx = kwargs['batch_idx']
# batch_idx = batch_idx
#
# # Anneal the temperature at regular intervals
# if self.batch_idx % self.anneal_interval == 0 and self.training:
# self.temp = np.maximum(self.temp * np.exp(- self.anneal_rate * batch_idx),
# self.min_temp)
#except:
# pass

Write Downloader for Fashion MNIST etc.

Write a downloader for several pytorch available datasets.
For each dataset, make a new file: get__data.py and save the file in ./data.
For each data we also want one new folder where everything is stored.
In best case, after everything is processed, we should delete the downloaded versions again (saves some memory).

Deep Dive Configurations

GaussMix

2nd best
anneal rate: 0.3
cat_weight: 2
cont_weight: 1
temperature: 11

3rd best
anneal_rate: 0.4
cat_weight: 1
cont_weight: 1
temperature: 31

Beta VAE
run on latent_dim = 5

UMAP:

implement UMAP functionality

MultiAttribute VAE

In general, it should work in the same ways as the AttrEncoder and AttrDecoder.
However, it must yield multi label predictions:

For Encoder:
Learn for each categorical variable a seperate embedding.
For this task the following link plus the AttrEncoder() implementation should be quite helpful:
https://machinelearningmastery.com/how-to-prepare-categorical-data-for-deep-learning-in-python/

For Decoder:
We must then map the representation back to the multilabel categorical variables. This shall work equivalently with the AttrDecoder. Right now it is not very clear how to do this, but this article seems quite promising
https://www.learnopencv.com/multi-label-image-classification-with-pytorch/

Evaluation:
we must also be quite certain with the evaluation, respective loss function.
The above article discusses this issue as well.

Further Readings:
1.) https://users.ics.aalto.fi/jesse/talks/Multilabel-Part01.pdf
2.) https://medium.com/@thevatsalsaglani/training-and-deploying-a-multi-label-image-classifier-using-pytorch-flask-reactjs-and-firebase-c39c96f9c427

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.