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

在使用Pytorch时我遇到如下错误

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

出错代码如下

 out = out.detach().numpy()

如下修改就可以

 out = out.detach().cpu().numpy()

你可能感兴趣的:(Python相关学习)