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

Posted AI浩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ])

以上是关于TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to的主要内容,如果未能解决你的问题,请参考以下文章

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

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

python3.4.0 input Can't convert 'int' object to str implicitly 如何正确输出?

成功解决TypeError: only size-1 arrays can be converted to Python scalars

TypeError: only integer scalar arrays can be converted to a scalar index

TypeError: only integer scalar arrays can be converted to a scalar index