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

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

Keras Layer
DL4J Equivalent
Supported

BatchNormalization

BatchNormalization

Yes


KerasBatchNormalization

source

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 UnsupportedKerasConfigurationException

Pass-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 (default 1e-3 in Keras)

  • momentum — momentum for updating running statistics (called decay in Keras 1, momentum in Keras 2)

  • center — whether a bias (beta) term is used

  • scale — 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 input InputType objects

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:

DL4J parameter name
Keras HDF5 tensor

gamma

scale parameter

beta

center parameter

mean

running mean

var

running variance

Parameters:

  • weights — map from parameter name to INDArray


Keras BatchNormalization Parameters

The following Keras parameters are mapped during import:

Keras parameter
DL4J configuration method

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?