nll_loss_forward_reduce_cuda_kernel_2d: 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: [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的形状,发现维度也没有问题,然后输出标签的值看一下

print(targets.min(), targets.max())

然后发现target的值==num_class,发现num_class的值写错了。
还有一种可能就是你的target的值不是从0开始的,是从1开始的也会报错。

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值