Skip to main content

A Python package offering implementations of state-of-the-art autoencoder architectures in PyTorch.

Project description

PyAutoencoder

A clean, modular PyTorch library for building and training autoencoders.

logo

PyPI License: MIT Stars


Highlights

PyAutoencoder is designed to offer simple and easy access to autoencoder frameworks. Here's what it offers:

  • Minimal, composable API
    You don't have to inherit from complicated base classes or learn a new training loop. Simply provide your own PyTorch nn.Module encoder and decoder, and plug them into the ready‑to‑use autoencoder wrappers. This makes it easy to experiment with different architectures (e.g. MLPs, CNNs) while reusing the same training pipeline.

  • Ready‑to‑use autoencoders The library ships with working implementations of autoencoders, each paired with their respective loss functions. You can start training in a few lines, without re‑implementing reconstruction likelihoods, KL divergence, or other boilerplate.

  • PyTorch compatibility
    The library is fully compatible with the PyTorch ecosystem, so models integrate naturally with modules, tensors, optimizers, and schedulers.

  • Lightweight, research‑oriented
    The library is intentionally minimal: no training loop frameworks, no heavy abstractions. This makes it well suited for research prototypes where you want control and transparency.

Status: The project is in an early but usable stage. Contributions, issues, and feedback are highly encouraged!

Currently implemented:

  • Autoencoder (AE)
  • Variational Autoencoder (VAE)

Installation

pip install pyautoencoder

Or install from source for development:

git clone https://github.com/andrea-pollastro/pyautoencoder.git
cd pyautoencoder
pip install -e .

Quick start

import torch
import torch.nn as nn
from pyautoencoder import VAE, VAELoss

# Define encoder/decoder
encoder = nn.Sequential(
    nn.Linear(784, 512), 
    nn.ReLU(),
    nn.Linear(512, 256)
)

decoder = nn.Sequential(
    nn.Linear(256, 512), 
    nn.ReLU(),
    nn.Linear(512, 784)
)

# Model
vae = VAE(encoder=encoder, decoder=decoder, latent_dim=32)

# Loss
criterion = VAELoss(beta=1.0, likelihood="gaussian")
optimizer = torch.optim.Adam(vae.parameters())
for x in dataloader:
    optimizer.zero_grad()
    out = vae(x)
    losses = criterion(out, x)
    losses.total.backward() # negative ELBO
    optimizer.step()

    # optional: log components
    log_likelihood = losses.components["log_likelihood"]
    kl_divergence = losses.components["kl_divergence"]

Built‑in models

  • AE — standard Autoencoder

    from pyautoencoder import AE, AutoencoderLoss
    ae = AE(encoder=encoder, decoder=decoder)
    criterion = AutoencoderLoss(likelihood="gaussian") # or bernoulli
    
  • VAE — Variational Autoencoder

    from pyautoencoder import VAE, VAELoss
    vae = VAE(encoder=encoder, decoder=decoder, latent_dim=32)
    criterion = VAELoss(beta=1.0, likelihood="gaussian") # or bernoulli
    

Examples

See the examples/ folder for runnable scripts showing example of usage.

License

This project is released under the MIT License. See LICENSE.

Citation

If you use this package in academic work, please cite:

@misc{pollastro2025pyautoencoder,
  author       = {Andrea Pollastro},
  title        = {pyautoencoder},
  year         = {2025},
  howpublished = {GitHub repository},
  url          = {https://github.com/andrea-pollastro/pyautoencoder}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyautoencoder-1.0.6.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyautoencoder-1.0.6-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file pyautoencoder-1.0.6.tar.gz.

File metadata

  • Download URL: pyautoencoder-1.0.6.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for pyautoencoder-1.0.6.tar.gz
Algorithm Hash digest
SHA256 381e3fe3f97b5ac323c356675de26a35da59d79ae6e530ccb6097f8abdb8a0e0
MD5 bf6210640d9b47c5b422ba343564faf9
BLAKE2b-256 79d5522b68395b98f0b34444f1f8e1a97a4de9a9f7140a0dc99f96585629dbaa

See more details on using hashes here.

File details

Details for the file pyautoencoder-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: pyautoencoder-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for pyautoencoder-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 20d343044e67b590b2b44ea6a174b05d0be168e9d4230b95d70aea3f28f5b329
MD5 21444c32ded199e0c3cf043b98453571
BLAKE2b-256 603add261e9553afa140c3e9d3ce5339ee58901a1a121f97b7328dec865b4ece

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page