Main Content

Deep Learning Custom Layers

Define custom layers for deep learning

You can define your own custom deep learning layer for your problem. You can specify a custom loss function using a custom output layers and define custom layers with or without learnable parameters. For example, you can use a custom weighted classification layer with weighted cross entropy loss for classification problems with an imbalanced distribution of classes. After defining a custom layer, you can check that the layer is valid, GPU compatible, and outputs correctly defined gradients.

Functions

expand all

checkLayerCheck validity of custom 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
findPlaceholderLayersFind placeholder layers in network architecture imported from Keras or ONNX
replaceLayerReplace layer in layer graph
assembleNetworkAssemble deep learning network from pretrained layers
PlaceholderLayerLayer replacing an unsupported Keras layer, ONNX layer, or unsupported functionality from functionToLayerGraph

Topics

Custom Intermediate Layers

Define Custom Deep Learning Layers

Learn how to define custom deep learning layers.

Define Custom Deep Learning Layer with Learnable Parameters

This example shows how to define a PReLU layer and use it in a convolutional neural network.

Define Custom Deep Learning Layer with Multiple Inputs

This example shows how to define a custom weighted addition layer and use it in a convolutional neural network.

Specify Custom Layer Backward Function

This example shows how to define a PReLU layer and specify a custom backward function.

Define Custom Deep Learning Layer for Code Generation

This example shows how to define a PReLU layer that supports code generation.

Custom Output Layers

Define Custom Classification Output Layer

This example shows how to define a custom classification output layer with sum of squares error (SSE) loss and use it in a convolutional neural network.

Define Custom Weighted Classification Layer

This example shows how to define and create a custom weighted classification output layer with weighted cross entropy loss.

Define Custom Regression Output Layer

This example shows how to define a custom regression output layer with mean absolute error (MAE) loss and use it in a convolutional neural network.

Specify Custom Output Layer Backward Loss Function

This example shows how to define a weighted classification layer and specify a custom backward loss function.

Network Composition and Nested Layers

Deep Learning Network Composition

Define custom layers containing layer graphs.

Define Nested Deep Learning Layer

This example shows how to define a nested deep learning layer.

Train Deep Learning Network with Nested Layers

This example shows how to train a network with nested layers.

Check Layer Validity

Check Custom Layer Validity

Learn how to check the validity of custom deep learning layers.