Python报错can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

原因:数据在cuda() ,需要将 float 型的tensor转化为numpy ,只能在cpu上进行。
报错行:

labels_=labels_.numpy().tolist()

根据提示用 Tensor.cpu() 修改:

labels_=labels_.cpu().numpy().tolist()

你可能感兴趣的:(Python,Python常见报错,numpy,python,开发语言)