在pytorch结合cuda下,直接使用

output.data.numpy()

会报标题错误:

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

解决办法:

output.data.cpu().numpy()

把CUDA tensor格式的数据改成numpy时,需要先将其转换成cpu float-tensor随后再转到numpy格式。 numpy不能读取CUDA tensor 需要将它转化为 CPU tensor。

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-02-24
  • 2022-12-23
  • 2021-08-07
  • 2021-04-14
猜你喜欢
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-03-28
  • 2022-02-09
  • 2021-09-08
  • 2022-12-23
相关资源
相似解决方案