Hi,
I am trying to do an image segmentation with PyTorch. Unfortunally I am getting an error while computing the loss:
RuntimeError: Assertion cur_target &gt;= 0 &amp;&amp; cur_target &lt; n_classes' failed. at c:\programdata\miniconda3\conda-bld\pytorch_1533090623466\work\aten\src\thnn\generic/SpatialClassNLLCriterion.c:110
I am using a CrossEntropyLoss:
loss_ce = nn.CrossEntropyLoss()

ce_loss = loss_ce(y_pred, y_true)

The size of y_pred is [4,1,256,256], the size of y_true is [4,256,256].
The values of y_true are [0,1].
In my opinion, that should fit, to the requirements listed in the PyTorch documentation for the CrossEntropyLoss (https://pytorch.org/docs/master/nn.html#torch.nn.CrossEntropyLoss 5):

CELoss.PNG717×201 20.9 KB

N = 4, C = 1, d1 = d2 = 256
I also checked the “autograd-flag” of the two variables:
print(y_true.requires_grad)
print(y_pred.requires_grad)

delivers
False
True

so that seems to be correct, too.
I can’t understand, why I am getting this error.
Can anybody help me please?
Thank you!