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:
ALReLU(default): current behavior from this project, with fixedalpha=0.01.TrainableALReLU: same formula with trainablealpha.
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:
- https://github.com/MStamatis/ALReLU/blob/main/scripts/train_mnist_keras_tf.py
- https://github.com/MStamatis/ALReLU/blob/main/scripts/train_mnist_torch.py
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42b48e1ba719bdaa8c9ed0d33f1d42507e045c119cbbe49284669ebb71e501ab
|
|
| MD5 |
c7c82a87611dba6588a64d0cdeb799ff
|
|
| BLAKE2b-256 |
61b8243c18c54a322197603278a6ce286a9eb7b137c36de5bb4b6f2477df3e54
|
Provenance
The following attestation bundles were made for alrelu_keras-0.1.2.tar.gz:
Publisher:
publish-keras.yml on MStamatis/ALReLU
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alrelu_keras-0.1.2.tar.gz -
Subject digest:
42b48e1ba719bdaa8c9ed0d33f1d42507e045c119cbbe49284669ebb71e501ab - Sigstore transparency entry: 976166944
- Sigstore integration time:
-
Permalink:
MStamatis/ALReLU@b587ada4742ad7de948504259fb8e27248320d16 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-keras.yml@b587ada4742ad7de948504259fb8e27248320d16 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4bd9c3486482ed1bd6750e9415e3e66ff95b65ab73cad1e127d7a4a39ec9bad
|
|
| MD5 |
99ce60cd43a4bfcbb385169bd68d99cd
|
|
| BLAKE2b-256 |
8013a3fe1333317f3839605e1aee99226f40559e694e86e724a69ada6ed437ce
|
Provenance
The following attestation bundles were made for alrelu_keras-0.1.2-py3-none-any.whl:
Publisher:
publish-keras.yml on MStamatis/ALReLU
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alrelu_keras-0.1.2-py3-none-any.whl -
Subject digest:
d4bd9c3486482ed1bd6750e9415e3e66ff95b65ab73cad1e127d7a4a39ec9bad - Sigstore transparency entry: 976166948
- Sigstore integration time:
-
Permalink:
MStamatis/ALReLU@b587ada4742ad7de948504259fb8e27248320d16 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-keras.yml@b587ada4742ad7de948504259fb8e27248320d16 -
Trigger Event:
workflow_dispatch
-
Statement type: