Comparing 4 classes of regularisers on a testbench to evaluate trade-off between reconstruction quality and latent disentanglement.
This repository serves as a boilerplate for a research project to compare four different information regularization mechanisms in Latent Variable Models: Standard VAE, VQ-VAE, Implicit Rank-Minimizing AE, and Sparse Coding.
-
Clone the repository and set up a virtual environment (recommended):
python -m venv .venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Weights & Biases (wandb) Setup: The testbench uses
wandbfor experiment tracking. Make sure to log in to your account:wandb login
Note: Runs are automatically logged to the
ciremteam entity.
Your task is to implement the specific regularization logic and loss functions. You do not need to worry about writing the training loop, metrics, or the autoencoder backbone.
-
Create your regularizer: Create a new file in the
models/directory (e.g.,models/vq_vae.py). -
Implement the interface: Your class must inherit from
BaseRegularizer(found inmodels/regularizers.py). You need to implement:forward(self, z_e): Applies the regularization (e.g. adds noise, quantizes) and returns the constrained latent vectorz_q.compute_loss(self, x, x_recon, z_e, z_q): Computes and returns a dictionary of losses. It must include at least'recon_loss','reg_loss', and'total_loss'.
-
Train your model: Update
train.pyto instantiate your custom regularizer instead of theIdentityRegularizer. Then run the script:python train.py --dataset mnist --epochs 20 --latent_dim 64
To see all available hyperparameters, run:
python train.py --help
models/base_ae.py: Contains the standard Convolutional Encoder and Decoder.models/regularizers.py: Contains theBaseRegularizerAbstract Base Class and anIdentityRegularizerexample.utils/metrics.py: Contains custom evaluation metrics (MSE, Linear Probe, Effective Rank, Active Code %).train.py: The main training and validation loop with wandb integration.