赞
踩
PyTorch 错误 RuntimeError: CUDA error: device-side assert triggered
flyfish
具体提示如下
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [2,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [20,0,0] Assertion `t >= 0 && t < n_classes` failed.
Traceback (most recent call last):
File "train_feature.py", line 65, in run
loss.backward()
File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/tensor.py", line 221, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/autograd/__init__.py", line 126, in backward
grad_tensors_ = _make_grads(tensors, grad_tensors_)
File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/autograd/__init__.py", line 51, in _make_grads
new_grads.append(torch.ones_like(out, memory_format=torch.preserve_format))
RuntimeError: CUDA error: device-side assert triggered
重点提示在这Assertion t >= 0 && t < n_classes
failed.
此错误的原因是模型输出的类别与标签的类别个数不一致
例如模型输出3类,但标签里有4类
可以该model的输出或者去除标签的一类,总之类别数目一致即可解决
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。