From d048ddc6db23d45a2b0b7a93f3521aac84f95e44 Mon Sep 17 00:00:00 2001 From: Lenoctambule <106790775+lenoctambule@users.noreply.github.com> Date: Wed, 8 Apr 2026 18:58:32 +0200 Subject: [PATCH] feat: packaging, project structure + updated README.md --- .gitignore | 2 ++ README.md | 31 +++++++++++++++----- mnist_test.py => examples/mnist_test.py | 10 ++++--- pyproject.toml | 23 +++++++++++++++ src/easyvae/__init__.py | 0 activations.py => src/easyvae/activations.py | 0 autoencoder.py => src/easyvae/autoencoder.py | 12 ++++---- layers.py => src/easyvae/layers.py | 2 +- utils.py => src/easyvae/utils.py | 0 9 files changed, 62 insertions(+), 18 deletions(-) rename mnist_test.py => examples/mnist_test.py (95%) create mode 100644 pyproject.toml create mode 100644 src/easyvae/__init__.py rename activations.py => src/easyvae/activations.py (100%) rename autoencoder.py => src/easyvae/autoencoder.py (95%) rename layers.py => src/easyvae/layers.py (98%) rename utils.py => src/easyvae/utils.py (100%) diff --git a/.gitignore b/.gitignore index d541758..50eb41c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ __pycache__ *.npz *.npy .venv +dist +*.egg-info \ No newline at end of file diff --git a/README.md b/README.md index 73b1b4e..edbb0e6 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,33 @@ ## Usage -1. Install requirements : +1. To install from source : ```sh -$ pip install -r requirements.txt +$ git clone git@github.com:lenoctambule/autoencoder.git +$ pip install -e autoencoder/ ``` -2. Optionally run mnist_test.py. +2. Optionally, run mnist_test.py to see it in action on the MNIST dataset. ```sh +$ cd examples $ py mnist_test.py ``` ## Training -Instatiate an `Autoencoder` object : +Instatiate an `ClassicalAutoencoder` or `VariationalAutoencoder` object : ```py -from autoencoder import Autoencoder -from activations import LeakyReLU +from easyvae.autoencoder import ClassicalAutoencoder, VariationalAutoencoder +from easyvae.activations import LeakyReLU -autoencoder = Autoencoder( +autoencoder = ClassicalAutoencoder( + [768, 64, 16], + [16, 64, 768], + 0.01, + LeakyReLU() +) +# or +autoencoder = VariationalAutoencoder( [768, 64, 16], [16, 64, 768], 0.01, @@ -30,11 +39,17 @@ And then via the `train_dataset` method to train over a dataset : ```py autoencoder.train_dataset(data) ``` -Or via the `train` to input each data points iteratively : +Or via the `train` method to input each data points iteratively : ```py autoencoder.train(v) ``` +After training, you can save your model via the `save` method and load that model using `load` method : +``` +autoencoder.save("mymodel.npy) +autoencoder.load("mymodel.npy") +``` + ## Inference Use your `Autoencoder` object with the `encode`, `decode`, `forward` methods like so : diff --git a/mnist_test.py b/examples/mnist_test.py similarity index 95% rename from mnist_test.py rename to examples/mnist_test.py index 2355006..1058590 100644 --- a/mnist_test.py +++ b/examples/mnist_test.py @@ -2,10 +2,12 @@ import matplotlib.pyplot as plt import numpy as np import os import signal -from autoencoder import (VariationalAutoencoder, # noqa - ClassicalAutoencoder, - AAutoencoder) -from activations import LeakyReLU +from easyvae.autoencoder import ( # noqa + VariationalAutoencoder, + ClassicalAutoencoder, + AAutoencoder + ) +from easyvae.activations import LeakyReLU def load_mnist() -> list[np.ndarray]: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ec0803a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[project] +name = "easyvae" +version = "1.0" +authors = [ + { name="Ravaka RALAMBOARIVONY", email="ravaka.rlb.pro@gmail.com" }, +] +description = "Python implementation of a Classical and Variational Autoencoders " +readme = "README.md" +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +license = "MIT" +license-files = ["LICEN[CS]E*"] + +[project.urls] +Homepage = "https://github.com/lenoctambule/autoencoder" +Issues = "https://github.com/lenoctambule/autoencoder/issues" + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/src/easyvae/__init__.py b/src/easyvae/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/activations.py b/src/easyvae/activations.py similarity index 100% rename from activations.py rename to src/easyvae/activations.py diff --git a/autoencoder.py b/src/easyvae/autoencoder.py similarity index 95% rename from autoencoder.py rename to src/easyvae/autoencoder.py index c650fb0..410699c 100644 --- a/autoencoder.py +++ b/src/easyvae/autoencoder.py @@ -1,10 +1,12 @@ import numpy as np -from utils import (dynamic_loss_plot_init, - dynamic_loss_plot_update, - dynamic_loss_plot_finish) +from .utils import ( + dynamic_loss_plot_init, + dynamic_loss_plot_update, + dynamic_loss_plot_finish + ) from tqdm import tqdm -from layers import DeepNNLayer, SampleLayer -from activations import ActivationFunc, Identity +from .layers import DeepNNLayer, SampleLayer +from .activations import ActivationFunc, Identity from abc import ABC, abstractmethod LOADER = ['⡿', '⣟', '⣯', '⣷', '⣾', '⣽', '⣻', '⢿'] diff --git a/layers.py b/src/easyvae/layers.py similarity index 98% rename from layers.py rename to src/easyvae/layers.py index 51c99e7..a79c6cd 100644 --- a/layers.py +++ b/src/easyvae/layers.py @@ -1,5 +1,5 @@ import numpy as np -from activations import ActivationFunc, Identity +from .activations import ActivationFunc, Identity class NNLayer: diff --git a/utils.py b/src/easyvae/utils.py similarity index 100% rename from utils.py rename to src/easyvae/utils.py