Skip to main content

ALReLU activation package for Keras with fixed and trainable alpha variants.

Project description

alrelu-keras

PyPI-installable Keras package for the ALReLU activation with 2 variants:

  1. ALReLU (default): current behavior from this project, with fixed alpha=0.01.
  2. TrainableALReLU: same formula with trainable alpha.

Formula used by both variants:

ALReLU(x, alpha) = max(abs(alpha * x), x)

Reference

ALReLU paper:

ALReLU: A different approach on Leaky ReLU activation function to improve Neural Networks Performance

https://arxiv.org/abs/2012.07564

Installation

pip install alrelu-keras

Keras requires a backend. For the common TensorFlow backend:

pip install alrelu-keras[tensorflow]

From source:

pip install .

Training Examples (MNIST)

Scripts:

  • Keras + TensorFlow: scripts/train_mnist_keras_tf.py
  • PyTorch: scripts/train_mnist_torch.py

Direct links:

Run commands (from repo root):

# Keras + TensorFlow
python scripts/train_mnist_keras_tf.py --epochs 5 --variant fixed --alpha 0.01
python scripts/train_mnist_keras_tf.py --epochs 5 --variant learnable --alpha 0.01

# PyTorch
python scripts/train_mnist_torch.py --epochs 5 --variant fixed --alpha 0.01
python scripts/train_mnist_torch.py --epochs 5 --variant learnable --alpha 0.01

Usage

1) Default ALReLU (current implementation behavior)

import keras
from alrelu_keras import ALReLU, alrelu

# As activation function
x = keras.ops.array([-2.0, -1.0, 0.0, 1.0], dtype="float32")
y = alrelu(x)  # alpha=0.01 by default

# As Keras layer
model = keras.Sequential(
    [
        keras.layers.Input(shape=(32,)),
        keras.layers.Dense(64),
        ALReLU(),  # fixed alpha
        keras.layers.Dense(10),
    ]
)

2) Trainable alpha variant

import keras
from alrelu_keras import TrainableALReLU

model = keras.Sequential(
    [
        keras.layers.Input(shape=(32,)),
        keras.layers.Dense(64),
        TrainableALReLU(alpha_initializer=0.01),  # alpha is trainable
        keras.layers.Dense(10),
    ]
)

Serialization / model loading

Both ALReLU, TrainableALReLU, and alrelu are registered as Keras-serializable objects. You can save/load models without manually passing custom_objects in standard Keras workflows.

Development

Install dev tools:

pip install -e .[dev]

Run tests:

pytest

Build package:

python -m build

License

MIT License. See LICENSE.

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

alrelu_keras-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

alrelu_keras-0.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file alrelu_keras-0.1.2.tar.gz.

File metadata

  • Download URL: alrelu_keras-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alrelu_keras-0.1.2.tar.gz
Algorithm Hash digest
SHA256 42b48e1ba719bdaa8c9ed0d33f1d42507e045c119cbbe49284669ebb71e501ab
MD5 c7c82a87611dba6588a64d0cdeb799ff
BLAKE2b-256 61b8243c18c54a322197603278a6ce286a9eb7b137c36de5bb4b6f2477df3e54

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.2.tar.gz:

Publisher: publish-keras.yml on MStamatis/ALReLU

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alrelu_keras-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: alrelu_keras-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alrelu_keras-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4bd9c3486482ed1bd6750e9415e3e66ff95b65ab73cad1e127d7a4a39ec9bad
MD5 99ce60cd43a4bfcbb385169bd68d99cd
BLAKE2b-256 8013a3fe1333317f3839605e1aee99226f40559e694e86e724a69ada6ed437ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.2-py3-none-any.whl:

Publisher: publish-keras.yml on MStamatis/ALReLU

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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