plt.plot(train_accuracy, label='training accuracy')
plt.plot(test_accuracy, label='validation accuracy')
plt.title('Accuracy at the end of each epoch')
plt.legend();
错误代码:
TypeError:无法将cuda:0设备类型Tensor转换为numpy。首先使用Tensor.cpu()将Tensor复制到主机内存中。
例如,test_accuracy是[tensor(0.6943,device ='cuda:0',dtype = torch.float64),Tensor(0.6891,device ='cuda:0',dtype = torch.float64),Tensor(0.7409,device ='cuda:0',dtype = torch.float64),Tensor(0.7202,device ='cuda:0',dtype = torch.float64),Tensor(0.7565,device ='cuda:0',dtype = torch.float64),Tensor(0.6891,device ='cuda:0',dtype = torch.float64),Tensor(0.7047,device ='cuda:0',dtype = torch.float64),Tensor(0.7409,device ='cuda:0',dtype = torch.float64),Tensor(0.6943,device ='cuda:0',dtype = torch.float64)]
1条答案
按热度按时间ifmq2ha21#
如错误所示,您需要首先将Tensor复制到主机内存。
试试看: