L2Decay
L2Decay实现L2权重衰减正则化,用于模型训练,有助于防止模型对训练数据过拟合。
具体实现中,L2权重衰减正则化的损失函数计算如下:
参数:
- coeff (float) – 正则化系数,默认值为0.0。
代码示例2
# Example2: set Regularizer in parameters
# Set L2 regularization in parameters.
# Global regularizer does not take effect on my_conv2d for this case.
from paddle import ParamAttr
from paddle.regularizer import L2Decay
my_conv2d = Conv2D(
in_channels=10,
kernel_size=1,
stride=1,
padding=0,
bias_attr=False)