Following is how I create the loss. Everything works fine when I use the CrossEntropyLoss, but with the DiceLoss, I get the RuntimeError
from myloss import DiceLoss

criterion = DiceLoss().cuda()
for i, data in enumerate(train_loader):
        inputs, labels = data
        inputs = Variable(inputs).cuda()
        labels = Variable(labels).cuda()
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()