报错如下:
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [26,0,0] Assertion `t >= 0 && t < n_classes` failed.
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [27,0,0] Assertion `t >= 0 && t < n_classes` failed.
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [28,0,0] Assertion `t >= 0 && t < n_classes` failed.
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [29,0,0] Assertion `t >= 0 && t < n_classes` failed.
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [30,0,0] Assertion `t >= 0 && t < n_classes` failed.
../aten/src/ATen/native/cuda/Loss.cu:271: nll_loss_forward_reduce_cuda_kernel_2d: block: [0,0,0], thread: [31,0,0] Assertion `t >= 0 && t < n_classes` failed.
Test Iter: 140/ 143. Data: 0.313s. Batch: 0.342s. Loss: 3.9630. top1: 6.09. top5: 22.77. : 98%|█████████▊| 140/143 [00:56<00:01, 2.48it/s]
Traceback (most recent call last):
File "./train.py", line 533, in <module>
main()
File "./train.py", line 314, in main
train(args, labeled_trainloader, unlabeled_trainloader, test_loader,
File "./train.py", line 450, in train
test_loss, test_acc = test(args, test_loader, test_model, epoch)
File "./train.py", line 508, in test
losses.update(loss.item(), inputs.shape[0])
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
然后在函数里输出inputs和targets的形状,发现维度也没有问题,然后输出标签的值看一下文章来源:https://www.toymoban.com/news/detail-820294.html
print(targets.min(), targets.max())
然后发现target的值==num_class,发现num_class的值写错了。
还有一种可能就是你的target的值不是从0开始的,是从1开始的也会报错。文章来源地址https://www.toymoban.com/news/detail-820294.html
到了这里,关于nll_loss_forward_reduce_cuda_kernel_2d: Assertion `t >= 0 && t < n__classes` failed.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!