📜  pytorch l2 正则化 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:23.648000             🧑  作者: Mango

代码示例2
loss = mse(pred, target)
 l1 = 0
 for p in net.parameters():
  l1 = l1 + p.abs().sum()
 loss = loss + lambda_l1 * l1
 loss.backward()
 optimizer.step()