错误1:
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().)
参考链接:https://blog.csdn.net/weixin_41735859/article/details/106471125
https://blog.csdn.net/u011622208/article/details/89707828
pytorch使用cv2读取图片,并转换成RGB顺序的时候,再用torch.from_numpy转换成tensor的时出错。
原因: 数组经过行上的切片操作,会改变数组的连续性
解决方法:
方法一:复制一份img保存到新的地址
img = img[:, :, ::-1]改为img = img[:, :, ::-1].copy()
方法二:将原有的img改为连续的img = img[:, :, ::-1]下一行插入
img = np.ascontiguousarray(img)
错误2:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 12, 3, 3], but got 3-dimensional input of size [3, 1280, 240] instead
原因: pytorch处理的数据是四维的,(b,c,h,w)
解决方法: input = input.unsqueeze(0)
错误3:
RuntimeError: “unfolded2d_copy” not implemented for ‘Half’
参考链接:https://blog.csdn.net/ynzzxc/article/details/114097206
原因: cpu训练不支持半精度数
解决方法: 将所有的.half()改成.float()