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

Core Layers

DL4J equivalents and API reference for Keras core layers — Dense, Flatten, Dropout, Reshape, Merge, Permute, and more.

Keras Core Layer Import

Core layers are implemented in the layers/core package of deeplearning4j-modelimport.

Support Summary

Keras Layer
DL4J Equivalent
Supported

Dense

DenseLayer

Yes

Activation

ActivationLayer

Yes

Dropout

DropoutLayer

Yes

Flatten

CnnToFeedForwardPreProcessor / RnnToFeedForwardPreProcessor

Yes

Reshape

ReshapePreProcessor

Yes

Merge

MergeVertex

Yes

Permute

PermutePreProcessor

Yes

RepeatVector

RepeatVector

Yes

Lambda

SameDiffLambda

Yes

ActivityRegularization

—

No

Masking

MaskZeroLayer

Yes

SpatialDropout1D

DropoutLayer (spatial 1D)

Yes

SpatialDropout2D

DropoutLayer (spatial 2D)

Yes

SpatialDropout3D

DropoutLayer (spatial 3D)

Yes


KerasPermute

source

Imports a Permute layer from Keras as a DL4J input preprocessor.

Constructor

Parameters:

  • layerConfig — dictionary containing Keras layer configuration

isInputPreProcessor

Returns true; Permute is implemented as an input preprocessor in DL4J.

getInputPreprocessor

Returns the DL4J InputPreProcessor corresponding to the Permute configuration.

getOutputType

Returns the output InputType after permutation.


KerasFlatten

source

Imports a Keras Flatten layer as a DL4J CnnToFeedForwardInputPreProcessor or RnnToFeedForwardPreProcessor, depending on the preceding layer type.

Constructor

isInputPreProcessor

Returns true; Flatten is implemented as an input preprocessor.

getInputPreprocessor

Selects the correct DL4J preprocessor based on inputType.

getOutputType


KerasReshape

source

Imports a Keras Reshape layer as a DL4J input preprocessor.

Constructor

isInputPreProcessor / getInputPreprocessor / getOutputType

Same pattern as KerasFlatten above.


KerasMerge

source

Imports a Keras Merge layer as a DL4J graph vertex. Supports add, multiply, subtract, average, maximum, and concatenate modes. The dot mode is not supported.

Constructor

getOutputType


KerasDense

source

Imports a Keras Dense layer as a DL4J DenseLayer.

Constructor

getDenseLayer

Returns the DL4J DenseLayer.

getOutputType

getNumParams

Returns the number of trainable parameters (weights + bias).

setWeights


KerasDropout

source

Imports a Keras Dropout layer as a DL4J DropoutLayer.

Constructor

getDropoutLayer

getOutputType


KerasMasking

source

Imports a Keras Masking layer as a DL4J MaskZeroLayer.


KerasSpatialDropout

source

Imports Keras SpatialDropout1D, SpatialDropout2D, and SpatialDropout3D layers as DL4J spatial dropout variants.


KerasLambda

source

Imports a Keras Lambda layer. The Lambda layer is mapped to a SameDiff-based lambda function in DL4J. The function body is serialized separately.


KerasRepeatVector

source

Imports a Keras RepeatVector layer, which repeats the input a fixed number of times along a new axis.


Notes

  • ActivityRegularization has no direct DL4J equivalent and will throw UnsupportedKerasConfigurationException at import time. Apply regularization directly in the layer configuration instead.

  • The Permute, Flatten, and Reshape layers are all implemented as InputPreProcessor instances in DL4J rather than as trainable layers.

Last updated

Was this helpful?