Downloads · 30 days
23
23% of all-time downloads
ayushshah/beta-vae-capacity-annealing-celeba
beta-vae-capacity-annealing-celeba is a unconditional image generation model from ayushshah. Use it for the unconditional image generation task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
A β-VAE trained on the CelebA dataset to learn disentangled latent representations of human faces. The model can generate faces, reconstruct images and enable controllable latent editing of attributes such as smile, p…
Downloads · 30 days
23
23% of all-time downloads
All-time downloads
102
Public
Parameters
3.5M
14.2 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors14.2 MB · 100%
From the Hugging Face model README
A β-VAE trained on the CelebA dataset to learn disentangled latent representations of human faces. The model can generate faces, reconstruct images and enable controllable latent editing of attributes such as smile, pose, etc.
<video src="https://github.com/AyushShahh/Beta-VAE-CelebA/raw/refs/heads/main/assets/video.mp4" autoplay loop controls width="800"> Your browser does not support the video tag. </video>This model is a β-Variational Autoencoder trained on 64×64 CelebA images with a 32-dimensional latent space and capacity annealing (γ=1000, C_max=50). The encoder maps images into a structured latent representation, while the decoder generates realistic face reconstructions and samples from latent vectors drawn from a Gaussian prior. The learned latent space exhibits partially disentangled factors corresponding to interpretable facial attributes such as smiling, face shape, background color, head rotation, etc. The model supports tasks including unconditional image generation, latent interpolation, feature extraction, and controllable latent editing. It is based on the paper Understanding Disentanglement in β-VAE with changes in the architecture and training.
Training code and model file is available on GitHub.<br> View the demo of latent editing on HuggingFace Spaces.
Instead of using simple convolutional blocks, the encoder and decoder are built using Residual Blocks. These residual connections help improve gradient flow during training, allowing the network to learn deeper representations while stabilizing optimization and improving reconstruction quality. You should avoid normalization like Batch Normalization because it interferes with the statistics but here Group Normalization is used to stabilize the training. Without it, the training is unstable and you will encounter exploding gradients, NaNs.
AdamW optimizer with weight decay 0 is used. Learning rate should not be kept above 3e-5 as it makes the training unstable and gradients will explode.
Hyperparameters:
Dataset used: jessicali9530/celeba-dataset (Kaggle). The images are center cropped to 148x148 and then resized to 64x64.
The directions/ folder contains latent direction tensors corresponding to semantic facial attributes. Each tensor has shape (32,), matching the dimensionality of the latent space. These directions are computed by taking the difference between the mean latent vectors of positive and negative samples for a given attribute in the CelebA annotations.
For example, a direction for smile is computed as:
direction = mean(latents_smiling) - mean(latents_not_smiling)
Moving along these directions modifies the corresponding attribute while keeping most other features relatively unchanged.
To edit an attribute, add the direction to the latent vector:
edited_latent = latent + strength * direction
where strength controls the intensity of the attribute change.
Positive values increase the attribute (e.g., more smile), while negative values reduce it.
Typical workflow:
This enables interactive latent editing such as:
Multiple directions can also be combined to perform compound edits.
You can also:
The model architecture is provided in the GitHub repository. To run the model locally, clone the repository and use the architecture implementation from there, then load the provided model weights and direction tensors from this Hugging Face repository.
Active dimensions are measured using the variance of latent activations across the dataset. Dimensions with higher variance are considered to encode meaningful factors of variation.
CelebA contains celebrity images and therefore does not represent the full diversity of human faces. As a result, the model may inherit biases present in the dataset and may perform unevenly across different demographics.