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

1. 在使用yolov5统计预测框数量时,在将Tensor类型的值转换成Numpy过程中出现的错误:TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

2. 原因:将一个在GPU上的Tensor类型转换为Numpy类型,没有将其先移动到CPU上。

3. 解决:

# x最初是Tensor类型
x = x.cpu().numpy()

猜你喜欢

转载自blog.csdn.net/weixin_44813538/article/details/133144110