I am using models.segmentation.deeplabv3_resnet101(pretrained=False, num_classes=12, progress=True) as model to train my own dataset.
Dataset consists of jpg and annotation in png(12 classes)
I transformed both to tensors using transforms.ToTensor()
training:
model.train()
outputs = model(inputs)
loss = criterion(outputs[‘out’], labels)
I get the following error
RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target’
I checked the dimension for output:
outputs[‘out’].size()
torch.Size([2, 12, 512, 512])
But the target has dimension:
labels.size()
torch.Size([2, 1, 512, 512])
How did you create the target?
If you are using nn.CrossEntropyLoss as your criterion, your target should be a LongTensor, have the shape [batch_size, height, width], and contain the class indices in the range [0, nb_classes-1].