RuntimeError Assertion cur_target = 0 cur_target n_classes failed

 

RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed
criterion = torch.nn.CrossEntropyLoss().cuda()
output=output.cuda()
target=target.cuda()
loss=criterion(output, target)

但我终于找到了我的错误:输出就像tensor([[0.5746,0.4254]])和目标一样tensor([2]),数字2超出了输出的指示

当我不使用GPU时,此错误消息是:

RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed.  at /opt/conda/conda-bld/pytorch-nightly_1547458468907/work/aten/src/THNN/generic/ClassNLLCriterion.c:93

 

你可能感兴趣的:(torch)