L2Decay

    L2Decay实现L2权重衰减正则化,用于模型训练,有助于防止模型对训练数据过拟合。

    具体实现中,L2权重衰减正则化的损失函数计算如下:

    参数:

    • coeff (float) – 正则化系数,默认值为0.0。

    代码示例2

    1. # Example2: set Regularizer in parameters
    2. # Set L2 regularization in parameters.
    3. # Global regularizer does not take effect on my_conv2d for this case.
    4. from paddle import ParamAttr
    5. from paddle.regularizer import L2Decay
    6. my_conv2d = Conv2D(
    7. in_channels=10,
    8. kernel_size=1,
    9. stride=1,
    10. padding=0,
    11. bias_attr=False)