For the complete documentation index, see llms.txt. This page is also available as Markdown.

Advanced Activations

DL4J equivalents and API reference for Keras advanced activation layers — LeakyReLU, PReLU, ELU, and ThresholdedReLU.

Keras Advanced Activation Layer Import

Advanced activation layers in Keras are parameterized activation functions implemented as full layers (with optional learnable parameters). Support is in the layers/advanced/activations package.

Support Summary

Keras Layer
DL4J Equivalent
Supported

LeakyReLU

ActivationLayer (LeakyReLU)

Yes

PReLU

PReLULayer

Yes

ELU

ActivationLayer (ELU)

Yes

ThresholdedReLU

ActivationLayer (ThresholdedReLU)

Yes


KerasLeakyReLU

source

Imports a Keras LeakyReLU layer as a DL4J ActivationLayer with a LeakyReLU activation function. The slope of the negative part (alpha) is read from the Keras configuration.

Constructor

public KerasLeakyReLU(Map<String, Object> layerConfig)
        throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException

Parameters:

  • layerConfig — dictionary containing the Keras layer configuration

getActivationLayer

Returns the DL4J ActivationLayer configured with a LeakyReLU activation.

getOutputType

Returns the same InputType as the input (activations are shape-preserving).


KerasPReLU

source

Imports a Keras PReLU layer as a DL4J PReLULayer. PReLU has per-channel (or per-element) learnable slope parameters; these are loaded from the HDF5 weights.

Constructor

getPReLULayer

Returns the DL4J PReLULayer with learned slope weights.

getOutputType

setWeights

Loads the PReLU slope parameters from the weight map.

Parameters:

  • weights — map from parameter name to INDArray containing the slope tensor


KerasThresholdedReLU

source

Imports a Keras ThresholdedReLU layer as a DL4J ActivationLayer with a thresholded ReLU activation. The threshold value is read from the Keras configuration.

ThresholdedReLU(x) = x if x > theta, else 0

Constructor

getActivationLayer

Returns the DL4J ActivationLayer configured with the threshold value.

getOutputType


ELU

ELU (Exponential Linear Unit) is supported as an activation function in standard layers (e.g., Dense(activation='elu')) and also as an explicit ELU layer. The importer handles both forms. When used as a standalone layer, it is mapped to a DL4J ActivationLayer with ActivationELU.


Example


Notes

  • Unlike Keras, where advanced activations are standalone layers, DL4J maps them to ActivationLayer (for fixed-parameter activations) or PReLULayer (for learned parameters). The layer count in model.summary() may therefore differ between DL4J and Keras.

  • Softmax used as a standalone Activation layer rather than a parameter is also supported and maps to ActivationLayer(ActivationSoftmax).

Last updated

Was this helpful?