Main Content

Custom Layers

Define custom layers for deep learning

For most tasks, you can use built-in layers. If there is not a built-in layer that you need for your task, then you can define your own custom layer. You can define custom layers with learnable and state parameters. After defining a custom layer, you can check that the layer is valid, GPU compatible, and outputs correctly defined gradients. For a list of supported layers, see List of Deep Learning Layers.

Functions

expand all

functionLayerFunction layer (Since R2021b)
checkLayerCheck validity of custom or function layer
setLearnRateFactorSet learn rate factor of layer learnable parameter
setL2FactorSet L2 regularization factor of layer learnable parameter
getLearnRateFactorGet learn rate factor of layer learnable parameter
getL2FactorGet L2 regularization factor of layer learnable parameter
networkDataLayoutDeep learning network data layout for learnable parameter initialization (Since R2022b)
dlnetworkDeep learning neural network
findPlaceholderLayersFind placeholder layers in network architecture imported from Keras or ONNX
replaceLayerReplace layer in neural network
PlaceholderLayerLayer replacing an unsupported Keras or ONNX layer

Topics

Custom Layers Overview

Define Custom Layers

Network Composition and Nested Layers