https://github.com/ahmetpala/vae-mnist

Variational Autoencoder (VAE) for MNIST using LSTM encoder and CNN decoder

https://github.com/ahmetpala/vae-mnist

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.9%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Variational Autoencoder (VAE) for MNIST using LSTM encoder and CNN decoder

Basic Info
  • Host: GitHub
  • Owner: ahmetpala
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 46.9 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 1 year ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Variational Autoencoder with LSTM and CNN on MNIST

Python TensorFlow License

This project builds a Variational Autoencoder (VAE) trained on the MNIST dataset.

  • The encoder is based on an LSTM.
  • The decoder uses Conv2DTranspose layers.
  • Implemented with Keras and TensorFlow.

Project structure

  • model.py – Defines the VAE architecture with a custom loss layer.
  • generator.py – Generates new MNIST-style digits using the trained decoder.
  • main.py – Loads data, trains the VAE, saves outputs, and visualizes training results.
  • utils - Contains useful functions for visualizations.
  • requirements.txt – Lists minimal dependencies.
  • .pre-commit-config.yaml – Defines formatting and linting rules.

Model architecture

  • Encoder: LSTM with 64 units → Dropout → two Dense layers for μ and σ → Sampling using the reparameterization trick.
  • Decoder: Dense → Reshape → two Conv2DTranspose layers.
  • Loss: Combines reconstruction loss (binary cross-entropy) with KL divergence.

How to run

  1. Clone the repository:

bash git clone https://github.com/ahmetpala/vae-lstm-cnn-mnist.git cd vae-lstm-cnn-mnist

  1. Create a virtual environment (optional but recommended):

bash python3.10 -m venv .venv source .venv/bin/activate

  1. Install dependencies:

bash pip install -r requirements.txt

  1. Run the training and evaluation:

bash python main.py

You can also specify the model parameters with different set of hyperparameters:

bash python main.py --latent_dim 4 --epochs 100 --batch_size 64

Default values:

  • latent_dim = 2
  • epochs = 100
  • batch_size = 128

This will: - Train the VAE for 100 epochs on MNIST - Save model files: vae.keras and decoder.keras - Save plots to the figures/ folder: - example_plots.png – sample input images - loss.png – training and validation loss - latent_space.png – 2D latent space - example_plots.png (overwritten) – 100 generated samples from latent grid


Code style

Pre-commit hooks are enabled for:

  • autopep8 (PEP8 formatting)
  • isort (import sorting)
  • flake8 (linting)

To activate:

bash pip install pre-commit pre-commit install

To manually run on all files:

bash pre-commit run --all-files


Requirements

  • Python 3.10+
  • TensorFlow 2.x
  • Keras
  • NumPy
  • Matplotlib

Outputs

All visual outputs are saved under the figures/ directory. Model files are saved in the project root.


Author

  • Ahmet Pala

License

This project is open-source and intended for educational use.

Owner

  • Login: ahmetpala
  • Kind: user

GitHub Events

Total
  • Push event: 34
  • Pull request event: 33
Last Year
  • Push event: 34
  • Pull request event: 33

Dependencies

requirements.txt pypi
  • keras ==3.9.1
  • matplotlib ==3.10.1
  • numpy ==2.2.4
  • tensorflow ==2.19.0