【PyTorch问题】can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy...略

问题描述:TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

问题详情:在获得模型结果output后希望转化为numpy的数组类型,但是无法直接使用numpy(),需要先将数据从GPU中取到CPU中

解决方法:先调用cpu()再调用numpy(),比如 predict_train.cpu().numpy()

(仅供参考)

你可能感兴趣的:(PyTorch,杂谈,pytorch)