l1正则化的方法
regularization_loss = 0
regularization_loss1 = 0
for param in net.parameters():
regularization_loss += torch.sum(abs(param))
#ww=net.parameters#net.weight
loss =loss
+0.25*regularization_loss1+0.5*regularization_loss
l2正则化的方法
regularization_loss = 0
regularization_loss1 = 0
for param in net.parameters():
regularization_loss += torch.sum(abs(param*param))
#ww=net.parameters#net.weight
loss =loss
+0.25*regularization_loss1+0.5*regularization_loss