Is there a way to assign labels passed to loss function different weights?

25 views
Skip to first unread message

Ilya Zhenin

unread,
Aug 28, 2017, 8:16:40 AM8/28/17
to Caffe Users
Particulary interested in segmentation task. I have to maps, image and according labels map. Does Caffe has a mechanic that will allow me to weight pixels in label map with different weigths?
For example pixel with coordinatex (x_1, y_1) gets a 3 x multiplier in the loss function, pixel with coordinates (x_2, y_2) gets 1 x multiplier, etc.

Hieu Do Trung

unread,
Aug 29, 2017, 10:50:30 PM8/29/17
to Caffe Users
I don't know if there is a better way, but I'll do it this way:

- split the final layer (right before loss layer) into multiple layers, the number of split layers is the number of labels map.
As with your example, " pixel with coordinatex (x_1, y_1)" will have it's own layer, pixel with coordinates (x_2, y_2) have it's own layer.
All those layers are exactly the same (because they are splitted from 1 layer).

- before feeding into loss layer, multiply each layer with it's corresponding mask.
The mask have values in range (0, 1): for pixel in (x_1, y_1), mask value will be 1, otherwise 0.
Loss layer for each splitted layer have it's own weight.
In your example, 1st lost layer will have loss_weight = 3, 2nd layer will have loss_weight = 1.
(Or, loss_weight = 0.75 and 0.25 if loss_weight is to be sum to 1.0, I'm not sure about this)

Ilya Zhenin

unread,
Aug 30, 2017, 10:39:54 AM8/30/17
to Caffe Users
Interesting, this should work. And again Caffe makes me feel like I am hitting nails with coconuts... :D

среда, 30 августа 2017 г., 5:50:30 UTC+3 пользователь Hieu Do Trung написал:
Reply all
Reply to author
Forward
0 new messages