Training using just custom loss python layers

47 views
Skip to first unread message

Shweta Philip

unread,
Sep 13, 2017, 3:37:51 PM9/13/17
to Caffe Users
Hi.

Is there a way to train a model using only custom python loss layers?
For example, I want to write my own L2 loss and softmax layers to train my network, this is because I want to add some regularization terms and normalize the loss using a different value.

Thanks!

Przemek D

unread,
Sep 18, 2017, 4:08:54 AM9/18/17
to Caffe Users
It should be possible. I think you might need to tell caffe explicitly that the python layer you're using is a loss layer and not an output blob, but that's easy, you just need to add the following line to your layer definition:
layer {
  name: "pyloss"
  type: "Python"
  ...
  loss_weight: 1
}

You will notice that this works slower than using built in, CUDA-accelerated layers though.

Also, many things can be accomplished by smart combinations of existing layers, see this for example - you don't always have to write an entire new layer.
Reply all
Reply to author
Forward
0 new messages