Custom input & output dimensions in neural network layers

조회 수: 1 (최근 30일)
AA
AA 2019년 1월 23일
답변: TARUN 2025년 8월 13일
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!

답변 (1개)

TARUN
TARUN 2025년 8월 13일
Hi @AA,
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:

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by