Normalization Layers
DL4J equivalents and API reference for Keras normalization layers — BatchNormalization.
Keras Normalization Layer Import
Normalization layer support is implemented in the layers/normalization package.
Support Summary
BatchNormalization
BatchNormalization
Yes
KerasBatchNormalization
Imports a Keras BatchNormalization layer as a DL4J BatchNormalization layer. Both training-mode (with learned gamma/beta) and inference-mode (with running mean/variance) parameters are loaded from the HDF5 file.
Constructor
public KerasBatchNormalization(Integer kerasVersion) throws UnsupportedKerasConfigurationExceptionPass-through constructor. kerasVersion is the major Keras version (1 or 2).
getBatchNormalizationLayer
public BatchNormalization getBatchNormalizationLayer()Returns the configured DL4J BatchNormalization layer. Configuration includes:
epsilon— small constant added to the variance for numerical stability (default1e-3in Keras)momentum— momentum for updating running statistics (calleddecayin Keras 1,momentumin Keras 2)center— whether a bias (beta) term is usedscale— whether a scale (gamma) term is used
getOutputType
Returns the output InputType. For BatchNormalization, the output shape is the same as the input shape.
Parameters:
inputType— array of inputInputTypeobjects
Returns: output InputType
getNumParams
Returns the number of trainable parameters (4: gamma, beta, running mean, running variance).
setWeights
Loads the four weight tensors from the weight map:
gamma
scale parameter
beta
center parameter
mean
running mean
var
running variance
Parameters:
weights— map from parameter name toINDArray
Keras BatchNormalization Parameters
The following Keras parameters are mapped during import:
axis
determines which dimension is normalized
momentum
decay() in DL4J builder
epsilon
eps() in DL4J builder
center
whether beta is included
scale
whether gamma is included
Note on axis: Keras BatchNormalization normalizes along the feature axis. In Keras with channels-last (NHWC), this is axis 3. DL4J uses channels-first (NCHW), where the feature axis is 1. The importer translates the axis value automatically.
Example
Notes
At inference time, DL4J uses the running mean and variance (not batch statistics), which matches Keras inference behavior.
LayerNormalization(Keras) has no direct equivalent in DL4J core and is not currently supported by the importer.
Last updated
Was this helpful?