How to get input size in designing custom layer?

To design custom layer, there is a template.
how to know the input size in construction to initialize learnable parameters?
The predict function has X. Do I initilize parameters in predict?
Plus, how to know the output shape of built-in layer?

2 Comments

I'm trying to figure out the exact same question but there is no answer from Mathworks. For initialization purposes, you can always feed the size of the activation matrix to the network as an input. But this is a pain, especially with very large networks. It would be great to have a way to obtain the input size automatically from within the custom layer as some of the default layers (e.g. conv layers) already do.
I have the exact same problem!
It seems th matlab built in fullyConnectedLayer first sets the inputSize to []
inputArguments.InputSize = [];
It then receives the input using the command in one of its inner classes (nnet.internal.cnn.layer.FullyConnected to be exact).
this.InputSize = getSizeForDims(X,'SC');
However, I am unable to locate getSizeForDims function to investigate. More importantly, I am unaware how this is obtained before training without giving any errors.

Sign in to comment.

Answers (1)

Read about deepNetworkDesigner. This will allow you to view the layers in a picture which is a GUI. It shows you all the information which is needed.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 22 Jun 2019

Answered:

on 9 Aug 2021

Community Treasure Hunt

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

Start Hunting!