wasidennis / AdaptSegNet

Learning to Adapt Structured Output Space for Semantic Segmentation, CVPR 2018 (spotlight)
850 stars 203 forks source link

Why are the dimensions of predict and target different in cross entropy? #46

Closed jsdd25 closed 5 years ago

jsdd25 commented 5 years ago

Hello! Your work is amazing! I have a question with the loss.py. I noticed that the cross entropy loss for semantic segmentation is implemented in the following code: loss = F.cross_entropy(predict, target, weight=weight, size_average=self.size_average) In this code, the dimension of predict is [h×w, c] and the dimension of target is [h×w]. I remember that when calculating the cross entropy loss, target and prediction should have the same dimensions. Maybe my problem is very stupid. This problem really bothers me. Thank you very much!!

idealwei commented 5 years ago

See F.cross_entropy, yon do not need to transform semantic label to one-hot label in Pytorch(implemented in F.cross_entropy funcion), but it's needed when you use Tensorflow.

jsdd25 commented 5 years ago

@idealwei Thank you very much!