This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

setL2Factor

Set L2 regularization factor of layer learnable parameter

Syntax

layer = setL2Factor(layer,parameterName,factor)

Description

example

layer = setL2Factor(layer,parameterName,factor) sets the L2 regularization factor of the parameter with the name parameterName in layer to factor.

For built-in layers, you can set the L2 regularization factor directly by using the corresponding property. For example, for a convolution2dLayer layer, the syntax layer = setL2Factor(layer,'Weights',factor) is equivalent to layer.WeightL2Factor = factor.

Examples

collapse all

Set and get the L2 regularization factor of a learnable parameter of a layer.

Define a custom PReLU layer. To create this layer, save the file preluLayer.m in the current folder.

Create a layer array including a custom layer preluLayer.

layers = [ ...
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    batchNormalizationLayer
    preluLayer(20,'prelu')
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer];

Set the L2 regularization factor of the 'Alpha' learnable parameter of the preluLayer to 2.

layers(4) = setL2Factor(layers(4),'Alpha',2);

View the updated L2 regularization factor.

factor = getL2Factor(layers(4),'Alpha')
factor = 2

Input Arguments

collapse all

Input layer, specified as a scalar Layer object.

Parameter name, specified as a character vector.

Example: 'Alpha'

Data Types: char

L2 regularization factor for the parameter, specified as a nonnegative scalar.

The software multiplies this factor with the global L2 regularization factor to determine the L2 regularization factor for the specified parameter. For example, if factor is 2, then the L2 regularization for the specified parameter is twice the global L2 regularization factor. You can specify the global L2 regularization factor using the trainingOptions function.

Example: 2

Introduced in R2017b