My batch size is 1, my image is 375  *1242 . *3, I’ve changed the numpy image to tensor image as 3 . 375 . 1242.
When I call
criterion = nn.CrossEntropyLoss().cuda()

loss = criterion(outputs, labels.long())

The error is showing as the tiltle:
RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [1, 3, 375, 1242]

I can’t figure out where is the problem, someone can help me? Thank you.
Here is the more detailed codes:
 for epoch in range(2):
    # loop over the dataset multiple times
    running_loss = 0.0
    for i, data in enumerate(dataloader):
        #get the inputs
        inputs, labels = data['image'], data['semantic']
        print(inputs.size())
        print(labels.size())
        # put to GPU
        labels = labels.cuda().float()
        #zero the parameter gradients
        optimizer.zero_grad()
        
        #forward + backward +optimize
        outputs = unet(inputs.cuda())
        outputs.cuda()
        print(outputs.size())
        print(labels.long().size())
        
        loss = criterion(outputs, labels.long())
        loss.backward()
        optimizer.step()
        
        #print statistics
        running_loss += loss.item()
        if i%20 ==19: 
            # print every 20 mini-batchs
            print('[%d, %5f] loss: %.3f'%(epoch +1, i+1, running_loss/20))
            running_loss = 0.0
print('Finish Training')