其他分享
首页 > 其他分享> > UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' i

UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' i

作者:互联网

错误提示:

 

 为pytorch不同版本进行更新迭代时引起的警告,某些参数被取代了

修正:

criterion = torch.nn.BCELoss(size_average=True)
改为:
criterion = torch.nn.BCELoss(reduction='mean')
criterion = torch.nn.BCELoss(size_average=False)
改为:
criterion = torch.nn.BCELoss(reduction='sum')

其它损失函数更改方法类似

原代码:

test_loss += F.nll_loss(output, target, size_average=False).item()

修正代码:

test_loss += F.nll_loss(output, target, reduction='sum').item()

 

标签:loss,use,nn,warnings,torch,warn,reduction,BCELoss,size
来源: https://www.cnblogs.com/pistachio0812/p/15180720.html