Skip to main content

PyAutoencoder

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

logo

PyPI Version Python CI Publish to PyPI License: MIT Downloads Docs 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)
  • Adaptive Group Variational Autoencoder (Ada-GVAE)

Documentation

Full documentation (installation, tutorials, API reference, and examples) is available at:

👉 https://andrea-pollastro.github.io/pyautoencoder/


Installation

pip install pyautoencoder

Or install from source for development:

git clone https://github.com/andrea-pollastro/pyautoencoder.git
cd pyautoencoder
pip install -e ".[dev]"   # package + test, docs and lint tools
pytest                    # run the test suite
ruff check .              # lint

Quick start

import torch
import torch.nn as nn
from pyautoencoder.variational import VAE

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

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

# Model
vae = VAE(encoder=encoder, decoder=decoder, latent_dim=latent_dim)
vae.build(torch.randn(1, 784))  # materialize the lazy layers before creating the optimizer
optimizer = torch.optim.Adam(vae.parameters())
for x in dataloader:  # assuming x of shape [B, 784] with values in [0, 1] (e.g. flattened MNIST)
    optimizer.zero_grad()
    out = vae(x)
    loss_results = vae.compute_loss(x, out, beta=1, likelihood='bernoulli')
    loss_results.objective.backward() # negative ELBO
    optimizer.step()
    # optional: log components
    log_likelihood = loss_results.diagnostics["log_likelihood"].item()
    kl_divergence = loss_results.diagnostics["kl_divergence"].item()

Examples

The examples/ directory contains runnable scripts, including:

  • mnist_ae.py – standard Autoencoder on MNIST
  • mnist_vae_kingma2013.py – reproduction of the MNIST VAE experiment from Kingma & Welling (2013), Fig. 2

These examples are also documented and explained in the online documentation.


License

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

Citation

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

@article{pollastro2025sincvae,
  title={SincVAE: A new semi-supervised approach to improve anomaly detection on EEG data using SincNet and variational autoencoder},
  author={Pollastro, Andrea and Isgr{\`o}, Francesco and Prevete, Roberto},
  journal={Computer Methods and Programs in Biomedicine Update},
  pages={100213},
  year={2025},
  publisher={Elsevier}
}

Acknowledgments

This work was funded by the PNRR MUR project PE0000013-FAIR (CUP: E63C25000630006).

Metadata

Release files for pyautoencoder 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyautoencoder 2.0.0
File Size Uploaded Provenance Actions
pyautoencoder-2.0.0.tar.gz 421.9 kB With provenance Details for pyautoencoder-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyautoencoder 2.0.0
File Interpreter ABI Platform Actions
pyautoencoder-2.0.0-py3-none-any.whl Python 3 none any Details for pyautoencoder-2.0.0-py3-none-any.whl

Total release size: 444.5 kB

Release files / pyautoencoder-2.0.0.tar.gz

Download URL pyautoencoder-2.0.0.tar.gz
Size 421.9 kB
Tags Source
SHA-256 checksum
How to use checksums
76492f010a61db77512490c5d6c678ae46f68b16de78dda0b6071c3d14064bf6
BLAKE2b-256 checksum
How to use checksums
9e5f618ce6000544e90425594b73e60b4b8e7e48cc5623ccbf3e7aedfd9fb8b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / pyautoencoder-2.0.0-py3-none-any.whl

Download URL pyautoencoder-2.0.0-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af671642c6e544f5b84db7864683dff168e9d45416e9eec8dfca6f6a7ddc4678
BLAKE2b-256 checksum
How to use checksums
8675313c456c6ef413038f10fdba881ea61fab5a050960d6fd20bc046042c333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for pyautoencoder 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyautoencoder-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page