My error’s details are as follows:
Traceback (most recent call last): File "train.py", line 184, in <module> train_hist = train(train_loader, num_classes, device, net, optimizer, criterion) File "train.py", line 123, in train loss = criterion(outputs, masks) File "/home/yp/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 489, in __call__ result = self.forward(*input, **kwargs) File "/media/yp/My Passport/dl_code2/satellite_segmentaion-master/utils/loss.py", line 76, in forward masks = torch.zeros(N, C, H, W).to(targets.device).scatter_(1, targets.view(N, 1, H, W), 1).permute(1, 0, 2, 3) RuntimeError: Invalid index in scatter at /opt/conda/conda-bld/pytorch_1550802451070/work/aten/src/TH/generic/THTensorEvenMoreMath.cpp:549
The code of loss:`
def forward(self, inputs, targets):
    N, C, H, W = inputs.size()

    softs = nn.functional.softmax(inputs, dim=1).permute(1, 0, 2, 3)
    masks = torch.zeros(N, C, H, W).to(targets.device).scatter_(1, targets.view(N, 1, H, W), 1).permute(1, 0, 2, 3)
    print("mIoULoss2d-------outputs'size:{},masks'size:{}".format(softs.size(),masks.size()))

    inters = softs * masks
    unions = (softs + masks) - (softs * masks)

    miou = 1. - (inters.view(C, N, -1).sum(2) / unions.view(C, N, -1).sum(2)).mean()

    return max(miou, self.nll_loss(nn.functional.log_softmax(inputs, dim=1), targets)) `  

How can I solve it? Thanks