报错:ValueError: At least one stride in the given numpy array is negative, and tensors with negative s

报错:ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy())

数据导入时报如上错误,错误代码如下

return {'imidx':torch.from_numpy(imidx), 'image': torch.from_numpy(tmpImg), 'label': torch.from_numpy(tmpLbl)}

解决方案
在修改torch.from_numpy(imidx)中的imidxnp.ascontiguousarray(imidx);tmpImg与tmpLbl使用相同的方式修改,修改结果如下:

return {'imidx':torch.from_numpy(np.ascontiguousarray(imidx)), 'image': torch.from_numpy(np.ascontiguousarray(tmpImg)), 'label': torch.from_numpy(np.ascontiguousarray(tmpLbl))}

你可能感兴趣的:(numpy,python,机器学习)