pytorch学习笔记———常见问题

错误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()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值