DiogenesAnalytics / autoencoder

Python library implementing various autoencoders.
https://colab.research.google.com/github/DiogenesAnalytics/autoencoder/blob/master/notebooks/demo/anomaly_detection.ipynb
MIT License
0 stars 0 forks source link

Feature: Implement Basic Minimal Autoencoder #11

Closed DiogenesAnalytics closed 9 months ago

DiogenesAnalytics commented 11 months ago

Problem

Need to implement the most basic autoencoder (has only 1 hidden layer).

Code

This code is directly from the previous issue #4:

"""A simple autoencoder to get you started."""
from dataclasses import dataclass
from typing import Any
from typing import ClassVar
from typing import Dict
from typing import Optional

from keras import layers

from .base import BaseAutoencoder
from .base import BaseLayerParams
from .base import DefaultParams

@dataclass
class MinimalLayerParams(BaseLayerParams):
    """Layer parameters class for minimal autoencoder."""

    # setup default values
    default_parameters: ClassVar[DefaultParams] = {
        "l0": (layers.InputLayer, {"input_shape": (784,)}),
        "l1": (layers.Dense, {"units": 32, "activation": "relu"}),
        "l2": (layers.Dense, {"units": 784, "activation": "sigmoid"}),
    }

    # setup instance layer params
    l0: Optional[Dict[str, Any]] = None
    l1: Optional[Dict[str, Any]] = None
    l2: Optional[Dict[str, Any]] = None

class MinimalAutoencoder(BaseAutoencoder):
    """A simple autoencoder to get you started."""

    _default_config = MinimalLayerParams()

    def __init__(self, model_config: Optional[MinimalLayerParams] = None) -> None:
        """Overrided base constructor to set the layer params class used."""
        # call super
        super().__init__(model_config=model_config)

References

DiogenesAnalytics commented 11 months ago

MNIST Results

Trained with MinimalAutoencoder using default parameters: minimal_autoencoder_results

DiogenesAnalytics commented 9 months ago

Implemented with: aecf1f4772b636be50d03a6dda62fcf0496114e4