$ cd ../
Generative VAE — bash

user@devops:~$ cat README.md

Generative VAE

# Description

VAE (Variational Autoencoder) implemented from scratch in PyTorch on Fashion-MNIST. Unlike a classical autoencoder, the VAE learns a probability distribution in the latent space (mean mu and log-variance) and uses the reparameterization trick (z = mu + eps*sigma) to generate brand new images. Architecture: Encoder 784->128->64->16 (Linear + ReLU layers), Decoder 16->64->128->784 with Sigmoid, 221,360 total parameters. Loss = BCE (reconstruction) + KL divergence (regularizing the latent space toward N(0, I)). Trained for 30 epochs on 5,000 samples on CPU (50s). Test results: Recon Loss 247.6, KL 11.46, 0.456 bits/pixel, no overfitting (train 255.5 vs test 259.0). Findings: (1) the latent space organizes by class - the PCA 2D projection of the 10,000 test images shows clear semantic clusters (sneakers, trousers, bags); (2) latent interpolation between an ankle boot and a bag produces smooth, plausible transitions; (3) each latent dimension encodes a visual attribute (width, neckline shape); (4) reconstructions are faithful but smoothed, typical of VAEs. Includes 6 visualizations: training curves, original vs reconstructed, latent space PCA 2D colored by class (55% explained variance), 64 images generated from noise, latent interpolation and latent traversal.

# Key features

$ VAE from scratch in PyTorch: Encoder 784->128->64->16 and Decoder 16->64->128->784 (221,360 params)

$ Reparameterization trick (z = mu + eps*sigma) for backprop through sampling

$ Loss = BCE + KL: balance between reconstruction fidelity and regularized latent space

$ Generates new images by sampling z ~ N(0, I) and decoding

$ Continuous latent space: interpolation between garments with smooth transitions (morphing)

$ Latent traversal: analysis of which visual attribute each latent dimension encodes

$ PCA 2D projection of the latent space colored by class (55% explained variance)

$ CPU-optimized: 30 epochs on 5,000 samples in 50s, no overfitting (test 259.0)

# Gallery

Training terminal
Generative VAE - Training terminal
64 generated images
Generative VAE - 64 generated images
Latent space PCA 2D
Generative VAE - Latent space PCA 2D
Original vs reconstruction
Generative VAE - Original vs reconstruction
Latent traversal
Generative VAE - Latent traversal

# Technologies used

PyTorch Python NumPy Matplotlib scikit-learn