Adding L1/L2 regularization in PyTorch?

后端 未结 5 2106
南旧
南旧 2020-12-24 01:20

Is there any way, I can add simple L1/L2 regularization in PyTorch? We can probably compute the regularized loss by simply adding the data_loss with the r

5条回答
  •  -上瘾入骨i
    2020-12-24 02:04

    Following should help for L2 regularization:

    optimizer = torch.optim.Adam(model.parameters(), lr=1e-4, weight_decay=1e-5)
    

提交回复
热议问题