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
LeakyReLU
ActivationLayer (LeakyReLU)
Yes
PReLU
PReLULayer
Yes
ELU
ActivationLayer (ELU)
Yes
ThresholdedReLU
ActivationLayer (ThresholdedReLU)
Yes
KerasLeakyReLU
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, UnsupportedKerasConfigurationExceptionParameters:
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
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 toINDArraycontaining the slope tensor
KerasThresholdedReLU
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) orPReLULayer(for learned parameters). The layer count inmodel.summary()may therefore differ between DL4J and Keras.Softmaxused as a standaloneActivationlayer rather than a parameter is also supported and maps toActivationLayer(ActivationSoftmax).
Last updated
Was this helpful?