zijundeng / pytorch-semantic-segmentation

PyTorch for Semantic Segmentation
MIT License
1.73k stars 393 forks source link

Loss Layer #21

Open herleeyandi opened 6 years ago

herleeyandi commented 6 years ago

Hello I still confuse here, for example what is our model output size and mask size. Suppose :

size = [batch, channel, height, width]
batch = 8
height = 96
width = 160
number of class = 2
model output = [8, 2, 96, 160] -> channel = 2 because class = 2
mask = [8, 1, 96, 160] -> channel = 1, which consist of 0 and 1 pixel value

How did you do this with CrossEntrophy2D?

zijundeng commented 6 years ago

Turn the mask into a 2-channel one (one channel for foreground class and another channel for background class). Or just use sigmod + BCELoss2D.

herleeyandi commented 6 years ago

So you means the mask is in one hot encoding form?, then how to do BCELoss2D?, I just see your code in CrossEntrophy2D you use nn.nllloss2D, if I am using BCELoss2D, should I use log_softmax after the BCELoss?, and for your CrossEntrophy2D why it not use sigmoid before nn.nllloss2D?

zijundeng commented 6 years ago

Yes, one hot encoding form. BCELoss can be used for any shape of data, which means you do not need to write an extra one.