RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int'
今天有空,把之前遇到的问题总结一下。
问题Traceback详情
Traceback (most recent call last):
File "E:/MyWorkspace/EEG/Pytorch/Train.py", line 79, in <module>
opti='Adam')
File "E:\MyWorkspace\EEG\Pytorch\Utils.py", line 133, in TrainTest_Model
validation_loss, validation_acc = Test_Model(net, testloader, criterion,True)
File "E:\MyWorkspace\EEG\EEGLearn-Pytorch\Utils.py", line 82, in Test_Model
loss = criterion(outputs, labels.cuda()) # GPU
File "D:\coson\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl

本文探讨了一次在使用PyTorch进行模型训练时遇到的RuntimeError,焦点在于labels参数类型不匹配导致的'nll_loss_forward_reduce_cuda_kernel_2d_index'未实现。通过分析源代码和官方文档,发现问题在于labels应为long类型而非Int。解决方法是将labels转换为long并配合GPU使用。
最低0.47元/天 解锁文章
1万+





