How to automatically initialize learnable parameters of a custom layer?
2 ビュー (過去 30 日間)
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!