TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to

问题描述:

Traceback (most recent call last):
  File "D:\rotation-yolov5-master\detect.py", line 173, in <module>
    detect()
  File "D:\rotation-yolov5-master\detect.py", line 114, in detect
    plot_one_box(xywh, im0, label=label, color=colors[int(cls)], line_thickness=3, path=path)
  File "D:\rotation-yolov5-master\utils\general.py", line 1316, in plot_one_box
    x = np.array(x)
  File "D:\ProgramData\Anaconda3\lib\site-packages\torch\_tensor.py", line 678, in __array__
    return self.numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

改为:

  x = np.array([i.data.item() for i in x ])

猜你喜欢

转载自blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/125533815