Custom input & output dimensions in neural network layers
1 view (last 30 days)
Show older comments
I would like to make my own custom layers for a deep neural network.
I'm wondering if it's possible to create layers with custom input and output dimensions...
For example, there might be some symmetries in my inputs, which I would like to hard code into the layer design via parameter sharing.
In the documentation https://uk.mathworks.com/help/deeplearning/ug/define-custom-deep-learning-layer.html, it mentions the dimensions for the mini-batches. Could I change those in custom layers? If so, would the trainNetwork function accept the data formatted that way?
Thanks!
0 Comments
Answers (1)
TARUN
on 13 Aug 2025
You can define your own custom layer if ‘deep learning toolbox’ does not provide the layer you require.
You can create custom deep learning layers in ‘MATLAB’ by defining a class that specifies properties (including learnable and state parameters), constructor, forward functions, and optionally backward and initialization functions.
Using ‘dlarray’ objects with dimension labels (e.g., ‘SSCB’, ‘CBT’) lets you handle different input/output formats, change dimensions, and support automatic differentiation without explicitly writing the backward pass.
Inherit from ‘nnet.layer.Formattable’ to enable formatted inputs and flexible dimension handling in custom layers.
For more information and detailed example, please go through the following link:
0 Comments
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!