pytorch报错“some of the strides of a given numpy array are negative“
在运行pytorch程序时,出现了如下的错误:

经过查找资料,发现是Opencv读取图片时的原因,原始报错代码片段:
img = cv2.imread(imgpath)
img = img[:,:,::-1]
img_tensor = torch.from_numpy(img)
修改后的代码:
img = cv2.imread(imgpath)
img = img[:,:,::-1].copy()
img_tensor = torch.from_numpy(img)

浙公网安备 33010602011771号