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

  • Post author:
  • Post category:其他




报错截图:

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

在这里插入图片描述



报错原因

numpy是cpu only的,所以需要先用cpu()转换到CPU



解决方法

加上cpu()

原代码:

在这里插入图片描述

修改后的代码:

在这里插入图片描述



版权声明:本文为xxxxxxbaby原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。