How to get input size in designing custom layer?
Show older comments
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
Jose Cortes-Briones
on 27 Nov 2019
Edited: Jose Cortes-Briones
on 27 Nov 2019
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.
Arman Ahmadian
on 9 Aug 2021
Edited: Arman Ahmadian
on 9 Aug 2021
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.
Answers (1)
KSSV
on 9 Aug 2021
0 votes
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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!