已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
我正在尝试使用GPU在Google Colab上训练CNN模型。我知道numpy
是一个仅限CPU的库,但如何消除此错误?模型训练完美,但仅在度量计算期间出现此错误。
我尝试使用cupy
和其他方法使其工作,但错误仍然存在。
已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
我正在尝试使用GPU在Google Colab上训练CNN模型。我知道numpy
是一个仅限CPU的库,但如何消除此错误?模型训练完美,但仅在度量计算期间出现此错误。
我尝试使用cupy
和其他方法使其工作,但错误仍然存在。
1条答案
按热度按时间flvlnr441#
错误消息表明您正在尝试将驻留在GPU上的Tensor直接转换为numpy数组。由于numpy是仅限CPU的库,因此您需要使用cpu()方法将Tensor从GPU复制到CPU内存,然后再将其转换为numpy数组。
在您的特定情况下,您需要确定在代码中尝试将CUDATensor转换为numpy数组的位置,并应用相同的方法。下面是一个示例:
您可能需要相应地修改代码。