报错显示:
RuntimeError: cuda runtime error (710) : device-side assert triggered at C:/cb/pytorch_1000000000000/work/aten/src\THC/generic/THCTensorMath.cu:29
用gpu运行不能显示出真正的错误原因,把模型和数据放在cpu上运行显示:
return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
IndexError: Target 61 is out of bounds.
这是由于类索引不在 的预期标签范围内[0, n_classes-1],
使用 torch.nn.CrossEntropyLoss () 它默认输入的标签范围是[0, n_classes-1] ,如果标签出现负数或者超出这个范围就会报错。将标签修改即可解决这个问题。