How to automatically initialize learnable parameters of a custom layer?

3 Ansichten (letzte 30 Tage)
Matlab DOES propagate configuration information to a custom layer when it automatically initializes learnable parameters, but NOT to the layer implementation.
Specifically, there's the configureForInputs() method in the Layer and CustomLayer classes which are invoked at the beginning of automatic learnable parameters initialization so that the layer can configure itself for input-dependent information (e.g., number of channels).
But while Layer propagates the call to inferSize() method of the layer implementation class (e.g., Convolution2D), CustomLayer does NOT do this (it calls setLearnablesToAutoInitialize() which sets the nested dlnetworks to auto-initialize but does NOT propagate the call to the layer implementation, i.e. user's code).
In addtion, there's another method in user's layer implementation of automatic initialization that isn't propagated to user's code by CustomLayer - initializeLearnableParameters():
initializeLearnableParameters() calls initialize() on any dlnet nested inside the custom layer, but doesn't propagate the call to user's implementation.
Note that only these two methods can modify the layer since only they return a possibly modified 'this' object.
PS A kludgy workaround is to define a dlnetwork and then to infer the configuration parameters therefrom, but it's a kludge and it wastes a lot of memory!

Akzeptierte Antwort

John Smith
John Smith am 10 Nov. 2022
It looks that Mathworks has added an option to initialize custom layers at network initialization time in R2022b.
There's now the initialize() method that the custom layer can provide and which will be called upon network initialization with a networkDataLayout object that describes the input. Furthermore, this method can modify the layer and return the modified layer to the caller for inclusion in the network.
See https://www.mathworks.com/help/deeplearning/ug/define-custom-deep-learning-layer.html

Weitere Antworten (0)

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by