Main Content

getLearnRateFactor

Get learn rate factor of layer learnable parameter

Description

factor = getLearnRateFactor(layer,parameterName) returns the learn rate factor of the learnable parameter with the name parameterName in layer.

For built-in layers, you can get the learn rate factor directly by using the corresponding property. For example, for a convolution2dLayer layer, the syntax factor = getLearnRateFactor(layer,'Weights') is equivalent to factor = layer.WeightLearnRateFactor.

example

factor = getLearnRateFactor(layer,parameterPath) returns the learn rate factor of the parameter specified by the path parameterPath. Use this syntax when the layer is a networkLayer or when the parameter is in a dlnetwork object in a custom layer.

example

factor = getLearnRateFactor(net,layerName,parameterName) returns the learn rate factor of the parameter with the name parameterName in the layer with name layerName for the specified dlnetwork object.

example

factor = getLearnRateFactor(net,parameterPath) returns the learn rate factor of the parameter specified by the path parameterPath. Use this syntax when the parameter is in a networkLayer or when the parameter is in a dlnetwork object in a custom layer..

example

Examples

collapse all

Set and get the learning rate factor of a learnable parameter of a custom SReLU layer.

Create a layer array containing the custom layer sreluLayer, attached to this example as a supporting file. To access this layer, open this example as a live script.

layers = [ ...
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    batchNormalizationLayer
    sreluLayer
    fullyConnectedLayer(10)
    softmaxLayer];

Set the learn rate factor of the LeftThreshold learnable parameter of the sreluLayer to 2.

layers(4) = setLearnRateFactor(layers(4),"LeftThreshold",2);

View the updated learn rate factor.

factor = getLearnRateFactor(layers(4),"LeftThreshold")
factor = 
2

Set and get the learning rate factor of a learnable parameter of a nested layer defined using network composition.

Create a residual block layer using the custom layer residualBlockLayer attached to this example as a supporting file. To access this file, open this example as a Live Script.

numFilters = 64;
layer = residualBlockLayer(numFilters)
layer = 
  residualBlockLayer with properties:

       Name: ''

   Learnable Parameters
    Network: [1x1 dlnetwork]

   State Parameters
    Network: [1x1 dlnetwork]

Use properties method to see a list of all properties.

View the layers of the nested network.

layer.Network.Layers
ans = 
  7x1 Layer array with layers:

     1   'conv_1'        2-D Convolution       64 3x3 convolutions with stride [1  1] and padding 'same'
     2   'batchnorm_1'   Batch Normalization   Batch normalization
     3   'relu_1'        ReLU                  ReLU
     4   'conv_2'        2-D Convolution       64 3x3 convolutions with stride [1  1] and padding 'same'
     5   'batchnorm_2'   Batch Normalization   Batch normalization
     6   'add'           Addition              Element-wise addition of 2 inputs
     7   'relu_2'        ReLU                  ReLU

Set the learning rate factor of the learnable parameter 'Weights' of the layer 'conv_1' to 2 using the setLearnRateFactor function.

factor = 2;
layer = setLearnRateFactor(layer,'Network/conv_1/Weights',factor);

Get the updated learning rate factor using the getLearnRateFactor function.

factor = getLearnRateFactor(layer,'Network/conv_1/Weights')
factor = 
2

Set and get the learning rate factor of a learnable parameter of a dlnetwork object.

Create a dlnetwork object

net = dlnetwork;

layers = [
    imageInputLayer([28 28 1],Normalization="none",Name="in")
    convolution2dLayer(5,20,Name="conv")
    batchNormalizationLayer(Name="bn")
    reluLayer(Name="relu")
    fullyConnectedLayer(10,Name="fc")
    softmaxLayer(Name="sm")];

net = addLayers(net,layers);

Set the learn rate factor of the 'Weights' learnable parameter of the convolution layer to 2 using the setLearnRateFactor function.

factor = 2;
net = setLearnRateFactor(net,'conv',Weights=factor);

Get the updated learn rate factor using the getLearnRateFactor function.

factor = getLearnRateFactor(net,'conv',"Weights")
factor = 
2

Create an array of layers containing an lstmLayer with 100 hidden units and a dropoutLayer with a dropout probability of 0.2.

layers = [lstmLayer(100,OutputMode="sequence",Name="lstm")
    dropoutLayer(0.2,Name="dropout")];

Create a network layer containing these layers.

lstmDropoutLayer = networkLayer(layers,Name="lstmDropout");

Use the network layer to build a network.

layers = [sequenceInputLayer(3)
    lstmDropoutLayer
    lstmDropoutLayer
    fullyConnectedLayer(10)
    softmaxLayer];

Create a dlnetwork object. You can also create a dlnetwork object by training the network using the trainnet function.

net = dlnetwork(layers);

Set the learning rate factor of the InputWeights learnable parameter of the LSTM layer in the first network layer to 2 using the setLearnRateFactor function.

factor = 2;
net = setLearnRateFactor(net,"lstmDropout_1/lstm/InputWeights",factor);

Get the updated learning rate factor using the getLearnRateFactor function.

factor = getLearnRateFactor(net,"lstmDropout_1/lstm/InputWeights")
factor = 
2

Set and get the learning rate factor of a learnable parameter of a custom nested layer defined using network composition in a dlnetwork object.

Create a dlnetwork object containing the custom layer residualBlockLayer attached to this example as a supporting file. To access this file, open this example as a Live Script.

inputSize = [224 224 3];
numFilters = 32;
numClasses = 5;

layers = [
    imageInputLayer(inputSize,'Normalization','none','Name','in')
    convolution2dLayer(7,numFilters,'Stride',2,'Padding','same','Name','conv')
    groupNormalizationLayer('all-channels','Name','gn')
    reluLayer('Name','relu')
    maxPooling2dLayer(3,'Stride',2,'Name','max')
    residualBlockLayer(numFilters,'Name','res1')
    residualBlockLayer(numFilters,'Name','res2')
    residualBlockLayer(2*numFilters,'Stride',2,'IncludeSkipConvolution',true,'Name','res3')
    residualBlockLayer(2*numFilters,'Name','res4')
    residualBlockLayer(4*numFilters,'Stride',2,'IncludeSkipConvolution',true,'Name','res5')
    residualBlockLayer(4*numFilters,'Name','res6')
    globalAveragePooling2dLayer('Name','gap')
    fullyConnectedLayer(numClasses,'Name','fc')
    softmaxLayer('Name','sm')];

dlnet = dlnetwork(layers);

View the layers of the nested network in the layer 'res1'.

dlnet.Layers(6).Network.Layers
ans = 
  7x1 Layer array with layers:

     1   'conv_1'        2-D Convolution       32 3x3x32 convolutions with stride [1  1] and padding 'same'
     2   'batchnorm_1'   Batch Normalization   Batch normalization with 32 channels
     3   'relu_1'        ReLU                  ReLU
     4   'conv_2'        2-D Convolution       32 3x3x32 convolutions with stride [1  1] and padding 'same'
     5   'batchnorm_2'   Batch Normalization   Batch normalization with 32 channels
     6   'add'           Addition              Element-wise addition of 2 inputs
     7   'relu_2'        ReLU                  ReLU

Set the learning rate factor of the learnable parameter 'Weights' of the layer 'conv_1' to 2 using the setLearnRateFactor function.

factor = 2;
dlnet = setLearnRateFactor(dlnet,'res1/Network/conv_1/Weights',factor);

Get the updated learning rate factor using the getLearnRateFactor function.

factor = getLearnRateFactor(dlnet,'res1/Network/conv_1/Weights')
factor = 
2

Input Arguments

collapse all

Input layer, specified as a scalar Layer object.

Parameter name, specified as a character vector or a string scalar.

Path to parameter in nested layer, specified as a string scalar or a character vector. A nested layer can be a layer within a networkLayer or a custom layer that itself defines a neural network as a learnable parameter.

If the input to getLearnRateFactor is a layer, then:

  • If the nested layer is in a network layer, the parameter path has the form "nestedLayerName/parameterName" where nestedlayerName is the name of the nested layer inside the network layer, and parameterName is the name of the parameter. If there are multiple levels of nested layers, then specify the path using the form nestedLayerName1/.../nestedLayerNameN/parameterName.

  • If the nested layer is a custom layer that itself defines a neural network as a learnable parameter, the parameter path has the form "propertyName/layerName/parameterName" where propertyName is the name of the property containing a dlnetwork object, layerName is the name of the layer in the dlnetwork object, and parameterName is the name of the parameter. If there are multiple levels of nested layers, then specify the path using the form "propertyName1/layerName1/.../propertyNameN/layerNameN/parameterName".

If the input to getLearnRateFactor is a dlnetwork object and the desired parameter is in a nested layer, then:

  • If the nested layer is in a network layer, the parameter path has the form "networkLayerName/nestedLayerName/parameterName" where networkLayerName is the name of the network layer, nestedlayerName is the name of the nested layer inside the network layer, and parameterName is the name of the parameter. If there are multiple levels of nested layers, then specify the path using the form "networkLayerName1/.../networkLayerNameN/nestedLayerName/parameterName".

  • If the nested layer is a custom layer that itself defines a neural network as a learnable parameter, the parameter path has the form "customLayerName1/propertyName/layerName/parameterName", where layerName1 is the name of the layer in the input dlnetwork object, propertyName is the name of the property of the layer containing a dlnetwork object, layerName is the name of the layer in the dlnetwork object, and parameterName is the name of the parameter. If there are multiple levels of nested layers, then specify the path using the form "customLayerName1/propertyName1/.../customLayerNameN/propertyNameN/layerName/parameterName".

Data Types: char | string

Neural network, specified as a dlnetwork object.

Layer name, specified as a string scalar or a character vector.

Data Types: char | string

Output Arguments

collapse all

Learning rate factor for the parameter, returned as a nonnegative scalar.

The software multiplies this factor by the global learning rate to determine the learning rate for the specified parameter. For example, if factor is 2, then the learning rate for the specified parameter is twice the current global learning rate. The software determines the global learning rate based on the settings specified with the trainingOptions function.

Version History

Introduced in R2017b

expand all