pytorch训练过程中loss出现NaN的原因及可采取的方法

在pytorch训练过程中出现loss=nan的情况

1.学习率太高。
2.loss函数
3.对于回归问题,可能出现了除0 的计算,加一个很小的余项可能可以解决
4.数据本身,是否存在Nan,可以用numpy.any(numpy.isnan(x))检查一下input和target
5.target本身应该是能够被loss函数计算的,比如sigmoid激活函数的target应该大于0,同样的需要检查数据集

https://blog.csdn.net/weixin_39092218/article/details/72915906

猜你喜欢

转载自blog.csdn.net/weixin_41278720/article/details/80778640