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.1.tar.gz (6.5 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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: alrelu_keras-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 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.1.tar.gz
Algorithm Hash digest
SHA256 c1abf50f4dd79c33a63ec1b4443cb73561a78cd1902474abd1e6672b6ce21df7
MD5 3e57ccefda5cfcf42dc5d8494bf68ccc
BLAKE2b-256 697a7345d6b2578ae367dafba71b192d745d83474ed591fe9370fd28b3bade2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: alrelu_keras-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fad9b3ec9bd1500dca0ffeb3ab48cd55c0ed9b716aecb298ad201ab2c16fe4c8
MD5 d7bb9ecfca80cded4ddcb107735f9f3a
BLAKE2b-256 91c754797646f5b58287479dcff02a2ca366517f1651fef9eb5646dcba3502ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.1-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