在PyTorch中添加L1/L2正则化? [英] Adding L1/L2 regularization in PyTorch?

查看:81
本文介绍了在PyTorch中添加L1/L2正则化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在PyTorch中添加简单的L1/L2正则化吗?我们可以通过简单地将 data_loss reg_loss 相加来计算正则损失,但是有没有任何明确的方法,PyTorch库提供的任何支持可以更轻松地完成它,而无需手动执行?

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 reg_loss but is there any explicit way, any support from PyTorch library to do it more easily without doing it manually?

推荐答案

这在

This is presented in the documentation for PyTorch. You can add L2 loss using the weight_decay parameter to the Optimization function.

这篇关于在PyTorch中添加L1/L2正则化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆