Adjust label weight bias in loss function?

2,277 views
Skip to first unread message

Marc Bickel

unread,
Sep 17, 2015, 6:52:38 AM9/17/15
to Caffe Users
Hi,

I try to segment images with the DeepLab method but with a different dataset.

In my case, I have only three labels. 0 is background, object A is label 1 and object B is label 2.
Object A (if in the image) takes roughly 15-25% of the image (label 0 pixels vs. label 1 pixels). For this label the segmentation works very well.

Object B, in contrast, are always small objects and take only 1-3% of the image (images can't be cropped to the size of object B).
This label learns very bad. Looking at the output score map, the prediction probabilities are close to 0 and also the location (if there is a small probability) is not aligned with the label 2 ground truth.

Now let's assume most of the pictures I have for training consist of 75% label 0 pixels, 22% label 1 pixels and 3% label 2 pixels.
My assumption is, that it might be cheaper at each iteration for the cost function, to fully ignore label 2 and only optimize filters for label 0 and label 1, because label 2 affects only a tiny fraction of the image and thus has only a small impact on the loss.

Does that make sense? And did anybody of you have similar problems?
And is there a way to adjust the loss function in caffe, so that an error with label 2 is punished more heavily as errors with label 1 or 0?


Thanks
Marc

Ali Mousavi

unread,
Oct 3, 2015, 7:35:50 PM10/3/15
to Caffe Users
Hi Marc,

Yes in caffe you have to adjust the Softmax loss layer. (e.g. look at this http://deepdish.io/2014/11/04/caffe-with-weighted-samples/)

I think Deeplab already does that. look at the commented part of the loss layer in the following prototxt to see how to weight the loss layer in deeplab : http://ccvl.stat.ucla.edu/ccvl/DeepLab-MSc/train.prototxt

Ruud

unread,
Sep 8, 2016, 1:27:26 PM9/8/16
to Caffe Users
Hi Marc,

Did you manage to weigh the labels according to Ali's suggestion?

Best,
Ruud

碧尧邵

unread,
Nov 27, 2017, 3:07:35 AM11/27/17
to Caffe Users
should the label of object B have bigger weight? for example, the weight of object A is 1 and the weight of object B is 2

Rex Cheng

unread,
Jan 20, 2018, 4:13:43 AM1/20/18
to Caffe Users
Hi,

I'm been trying to assign higher weights to a specific label. I came across a implementation on GitHub which can increase the weight of a class in a SoftmaxWithLoss layer. It was not compatible with the current Caffe so I modified it a bit: https://github.com/silver-rush/Weighted_Softmax_Loss

Hope it helps.


On Thursday, September 17, 2015 at 6:52:38 PM UTC+8, Marc Bickel wrote:
Reply all
Reply to author
Forward
0 new messages