How can I have multiple losses in a network in Caffe?

风流意气都作罢 提交于 2019-12-22 14:53:10

问题


If I define multiple loss layers in a network, will there be multiple back propagation happening from those ends to the beginning of the network? I mean, do they even work that way?

Suppose I have something like this:

Layer1{
}
Layer2{
}
...
Layer_n{
}
Layer_cls1{
bottom:layer_n
top:cls1
}
Layer_cls_loss1{
type:some_loss
bottom:cls1
top:loss1
}
Layer_n1{
bottom:layer_n
..
}
Layer_n2{
}
...
layer_n3{
}
Layer_cls2{
bottom:layer_n3
top:cls2
}
Layer_cls_loss2{
type:some_loss
bottom:cls2
top:loss2
}
layer_n4{
bottom:layer_n3
..
}
...
layer_cls3End{
top:cls_end
bottom:...
}
loss{
bottom:cls_end
top:loss:
type: someloss
}

So basically suppose instead of having one classification/loss per each network, we have several in between as well.

And in case they work, how could I add all the losses together and make my final loss the summation of all previous losses?


回答1:


Caffe does this for you.
Furthermore, for each loss layer you have loss_weight parameter that allows you to decide how influential this specific loss is with respect to all other losses in the net.
Overall, the loss minimized by caffe is the weighted sum of all loss layers in the model.



来源:https://stackoverflow.com/questions/42344012/how-can-i-have-multiple-losses-in-a-network-in-caffe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!