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
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
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
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
Imports a Keras Reshape layer as a DL4J input preprocessor.
Constructor
isInputPreProcessor / getInputPreprocessor / getOutputType
Same pattern as KerasFlatten above.
KerasMerge
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
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
Imports a Keras Dropout layer as a DL4J DropoutLayer.
Constructor
getDropoutLayer
getOutputType
KerasMasking
Imports a Keras Masking layer as a DL4J MaskZeroLayer.
KerasSpatialDropout
Imports Keras SpatialDropout1D, SpatialDropout2D, and SpatialDropout3D layers as DL4J spatial dropout variants.
KerasLambda
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
Imports a Keras RepeatVector layer, which repeats the input a fixed number of times along a new axis.
Notes
ActivityRegularizationhas no direct DL4J equivalent and will throwUnsupportedKerasConfigurationExceptionat import time. Apply regularization directly in the layer configuration instead.The Permute, Flatten, and Reshape layers are all implemented as
InputPreProcessorinstances in DL4J rather than as trainable layers.
Last updated
Was this helpful?