Hi Abishek!



 abhi8569:

I have 3 different class to segment whihc is denoted by [0,1,2] in the ground truth image. These are the output from different steps:
Model Output : torch.Size([5, 3, 120, 160]) #batch,channel,height,width
Argmax Output : torch.Size([5, 120, 160]) #check maximum along the channel axis
Ground Truth : torch.Size([5, 120, 160])

I am using below code snippet to find the loss using CrossEntropy
loss_seg = criterion_seg(x, label)
#x = output from argmax
#label = ground truth



I assume that criterion_seg is something you wrote yourself
that basically forwards its arguments to F.cross_entropy().
You most likely should pass Model Output in place of x as
the first argument of criterion_seg, and don’t use argmax()
at all.


While doing so I am getting below error
RuntimeError: "host_softmax" not implemented for 'Long'



This is (most likely) telling you that your are passing the Long
result of argmax() to F.cross_entropy() which is expecting
Float as its “predictions” input.  (cross_entropy()'s
target – your label – should, however, be a LongTensor
containing integer class labels ranging over [0, 1, 2]).
Without seeing your code for criterion_seg() I don’t really
know, but I would have expected you to get a dimensions
mismatch error before the type error.
Based on what I think you are doing, x should be your model
output, a FloatTensor of shape [5, 3, 120, 160], where
nBatch = 5, and nClass = 3, containing raw-score logits
that run from -inf to inf.  label should be your ground truth,
a LongTensor of shape [5, 120, 160], containing integer
class labels in [0, nClass - 1], inclusive.
The point is you don’t want to convert a set of nClass logits
(or probabilities) to a single integer class label (by using
argmax()) and then pass it to cross_entropy(), because
that is not what cross_entropy() is expecting.
Good luck.
K. Frank