RuntimeError: cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/THCUNN/generic/ClassNLLCriterion.cu:111

When train fcn, it happended cuda runtime error(59).Then, I tried to run it on CPU, getting errors as follows:
0it [00:00, ?it/s]/home/zqc/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py:2351: UserWarning: nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.
warnings.warn(“nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.”)
/home/zqc/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py:2423: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
“See the documentation of nn.Upsample for details.”.format(mode))
/home/zqc/anaconda3/lib/python3.6/site-packages/torch/nn/_reduction.py:49: UserWarning: size_average and reduce args will be deprecated, please use reduction=‘sum’ instead.
warnings.warn(warning.format(ret))
/opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/THCUNN/ClassNLLCriterion.cu:105: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [29,0,0] Assertion t >= 0 && t < n_classes failed.
THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/THCUNN/generic/ClassNLLCriterion.cu line=111 error=59 : device-side assert triggered

Traceback (most recent call last):
File “train.py”, line 278, in
main()
File “train.py”, line 223, in main
loss = loss_fn(output, target)
File “/home/zqc/yxh/PaperExperiment/semseg/loss.py”, line 27, in cross_entropy2d
weight=weight, size_average=False)
File “/home/zqc/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py”, line 1790, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/THCUNN/generic/ClassNLLCriterion.cu:111

Your target tensor seems to contain out of bounds class indices.
Make sure that your class indices are in the range [0, nb_classes-1].

1 Like

Thank you!I checked out the value of image, but forgot to check the “nb_classes”.