Skip to content

Repository files navigation

Convolutional Variational Autoencoder

image alt

A PyTorch implementation of a Convolutional Variational Autoencoder for image generation and reconstruction, specifically designed for face datasets.

Generating a face from sampling from the latent space

(it suffers from posterior collapse , it always generates a face with the same features -> styleGAN architectue solves this problem , check my implementation of it StyleGAN Repo )

image alt image alt image alt image alt

Features

  • Convolutional Architecture: Encoder-decoder structure with convolutional and transposed convolutional layers
  • Perceptual Loss: VGG19-based perceptual loss for improved reconstruction quality
  • Beta Scheduling: Gradual increase of KL divergence weight during training
  • Checkpointing: Resume training from saved checkpoints
  • Memory Efficient: Built-in memory management for GPU training

Model Architecture

  • Input: 128×128 RGB images
  • Encoder: 3 convolutional blocks (32→64→128 channels) with LayerNorm
  • Latent Space: 256-dimensional latent vector
  • Decoder: 3 transposed convolutional blocks with skip connections

Loss Components

  1. Reconstruction Loss: Binary Cross-Entropy + MAE
  2. KL Divergence Loss: Regularization term with beta scheduling
  3. Perceptual Loss: VGG19 feature matching (optional, enabled after epoch 10)

Quick Start

git clone https://github.com/HajarHAMDOUCH01/Convolutiional_VAE
pip install -r requirements.txt

# Train model
python train_vae.py

Training Configuration

Key parameters in training_config.py:

  • batch_size: 64
  • lr: 1e-4
  • num_epochs: 300
  • beta: KL weight (starts at 0.0, increases every 10 epochs => maximum 1.0)
  • z_dim: Latent dimension (256)

Releases

Packages

Contributors

Languages