LArbys / LArCV

Liquid Argon Computer Vision
11 stars 9 forks source link

class-wise weighting capability #44

Closed drinkingkazu closed 8 years ago

drinkingkazu commented 8 years ago

FCN training so far has loss shot down to ~0.01 pretty quickly which is suspected due to ~99% of pixels being a background. One solution to this is to introduce weight-per-class when computing loss and provide smaller weight for background pixel.

The work is done by someone else already: https://github.com/mohamed-ezz/caffe/commit/876e387a6d7f8974f68f42beacd3728b4fc92ff7

Just need to be ported in.

drinkingkazu commented 8 years ago

... and this is now implemented in class_weights branch which came off of apicaffe_cleanup branch. I only implemented for class-wise weight. The author mentioned in the original post above had also spatial variation option (i.e. literally weight image per class), which might be useful given our detector has some local regions with features (like dead wires). I can extend the implementation in future if needed, but will stop for now.

drinkingkazu commented 8 years ago

The branch is also merged back into apicaffe_cleanup branch

vgenty commented 8 years ago

as a reference for how to use this, include in the loss layer prototxt definition the following parameter class_loss_weights. As an example for increasing the importance for 5 of 6 classes

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "score"
  bottom: "label"
  top: "loss"
  loss_param {
    class_loss_weights: 1                # class 0
    class_loss_weights: 100              # class 1
    class_loss_weights: 100              # class 2
    class_loss_weights: 100              # class 3
    class_loss_weights: 100              # class 4
    class_loss_weights: 100              # class 5
  }
}