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 specify a custom loss function using a custom output layer and 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
Topics
Custom Layers Overview
- Define Custom Deep Learning Layers
Learn how to define custom deep learning layers. - Define Custom Deep Learning Intermediate Layers
Learn how to define custom deep learning intermediate layers. - Define Custom Deep Learning Output Layers
Learn how to define custom deep learning output layers. - Check Custom Layer Validity
Learn how to check the validity of custom deep learning layers. - Import Custom Layer into Deep Network Designer
This example shows how to import a custom classification output layer with the sum of squares error (SSE) loss and add it to a pretrained network in Deep Network Designer. - Assemble Network from Pretrained Keras Layers
This example shows how to import the layers from a pretrained Keras network, replace the unsupported layers with custom layers, and assemble the layers into a network ready for prediction. - Replace Unsupported Keras Layer with Function Layer
This example shows how to import the layers from a pretrained Keras network, replace the unsupported layers with function layers, and assemble the layers into a network ready for prediction.
Custom Intermediate 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. - Define Custom Deep Learning Layer with Formatted Inputs
This example shows how to define a custom layer with formatteddlarray
inputs. - Define Custom Recurrent Deep Learning Layer
This example shows how to define a peephole LSTM layer and use it in a neural network. - Specify Custom Layer Backward Function
This example shows how to define a PReLU layer and specify a custom backward function. - Custom Layer Function Acceleration
Accelerate custom layer forward and predict functions by caching and reusing traces. - 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 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 custom classification output layer with sum of squares error (SSE) loss 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.