File “E:\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 489, in call
result = self.forward(*input, **kwargs)
File “E:\python_workspace\codee\TorchSeg\model\dfn\voc.dfn.R101_v1c\network.py”, line 179, in forward
loss1 = self.criterion(pred_out[1], label)
File “E:\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 489, in call
result = self.forward(*input, **kwargs)
File “E:\anaconda3\lib\site-packages\torch\nn\modules\loss.py”, line 904, in forward
ignore_index=self.ignore_index, reduction=self.reduction)
File “E:\anaconda3\lib\site-packages\torch\nn\functional.py”, line 1970, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
File “E:\anaconda3\lib\site-packages\torch\nn\functional.py”, line 1295, in log_softmax
ret = input.log_softmax(dim)
RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at C:/a/w/1/s/tmp_conda_3.6_090826/conda/conda-bld/pytorch_1550394668685/work/aten/src/ATen/native/cuda/SoftMax.cu:545:
The error happens in the code
if label is not None and aux_label is not None:
loss0 = self.criterion(pred_out[0], label)
loss1 = self.criterion(pred_out[1], label)
loss2 = self.criterion(pred_out[2], label)
loss3 = self.criterion(pred_out[3], label)
The I try the code downside.
criterion = nn.CrossEntropyLoss(reduction=‘mean’,ignore_index=255)
input=np.random.randint(255,size=(2,21,512,512))
input= torch.from_numpy(input)
target=np.random.randint(255,size=(2,512,512))
target= torch.from_numpy(target)
loss=criterion(input.float(),target.long())
Then the ‘RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes’ failed.’ happen.
But when i try the code
loss=nn.CrossEntropyLoss()
input = torch.randn(3,21,50,50, requires_grad=True)
target = torch.empty(3,50,50, dtype=torch.long).random_(5)
output = loss(input, target)
No RuntimeError happen.What is the difference of the last two codes?How can I adjust the second code?And how can I adjust the first code?
Please give me a hand