How to create a PyCaffe loss layer with two tops?

28 views
Skip to first unread message

Raúl Gombru

unread,
Dec 4, 2017, 9:35:09 AM12/4/17
to Caffe Users
Hello,

I want to create a PyCaffe loss layer with two tops. The reason is that I want to output from the loss layer the loss and another value to monitor it. 
If I just add two tops as:

PyCaffe layer: 

top[0].data[...] = loss
top[1].data[...] = value_to_monitor


prototxt:

layer {
name: "lossCustom"
type: "Python"
bottom: "fc2"
bottom: "label"
top: "loss"
top: "value_to_monitor"
python_param {
module: "my_loss_layer"
layer: "myLossLayer"
}
loss_weight: 1
}

I get this error:

Check failed: top.size() == num_loss_weights (2 vs. 1) loss_weight must be unspecified or specified once per top blob.

But I don't need to weight two losses (btw, how weight values should be written in the prototxt to do that?), I just need to output another value.
How can I do that?

Thanks

Przemek D

unread,
Dec 5, 2017, 2:57:47 AM12/5/17
to Caffe Users
If you specify a loss_weight for a layer, you must do so for each top blob of that layer individually. If you have 2 top blobs, there must be 2 loss_weights. If you want to only use one top blob as a loss, I think it is enough to set a positive loss weight for that blob, while setting the one corresponding to your "monitor" blob to zero.
Try this:
layer {
  name: "myLayer"
  //...
  top: "loss"
  top: "monitor"
  //...
  loss_weight: 1
  loss_weight: 0
}
Message has been deleted

Raúl Gombru

unread,
Dec 5, 2017, 5:58:34 AM12/5/17
to Caffe Users
Thanks! I understood that, but I didn't know the syntax. Closing.
Reply all
Reply to author
Forward
0 new messages