Train deeplabv3 on your own dataset

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 do I resolve this ? Thanks in advance

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].

Thanks a lot for your reply.
Now I am stuck on the following:

Essentially converting the [batch_size, nb_classes, height, width] from output with 12 classes.

predictions[‘out’]
Out[76]:
tensor([[[[-0.0465, -0.0465, -0.0465, …, -0.0556, -0.0556, -0.0556],
[-0.0465, -0.0465, -0.0465, …, -0.0556, -0.0556, -0.0556],
[-0.0465, -0.0465, -0.0465, …, -0.0556, -0.0556, -0.0556],
…,

predictions[‘out’].size()
Out[77]: torch.Size([1, 12, 300, 400])

I’ve answered in the other thread.

Yes, thank you for the quick responses