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

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/ 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/ 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/ UserWarning: size_average and reduce args will be deprecated, please use reduction=‘sum’ instead.
/opt/conda/conda-bld/pytorch_1544199946412/work/aten/src/THCUNN/ 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/ line=111 error=59 : device-side assert triggered

Traceback (most recent call last):
File “”, line 278, in
File “”, line 223, in main
loss = loss_fn(output, target)
File “/home/zqc/yxh/PaperExperiment/semseg/”, line 27, in cross_entropy2d
weight=weight, size_average=False)
File “/home/zqc/anaconda3/lib/python3.6/site-packages/torch/nn/”, 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/

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”.