pytorch判断NaN

 

pytorch判断NaN

 

You can always leverage the fact that nan != nan:

data = torch.tensor([1, 2, np.nan])
tensor([  1.,   2., nan.])
data[data != data]
tensor([ 0,  0,  1], dtype=torch.uint8)

 if ciou[ciou != ciou].size(0)>0:
        print('nan')

With pytorch 0.4 there is also torch.isnan:

>>> torch.isnan(x)
tensor([ 0,  0,  1], dtype=torch.uint8)

这个待测试:

4.数据本身,是否存在Nan,可以用numpy.any(numpy.isnan(x))检查一下input和target 

你可能感兴趣的:(torch)