How can I get Top-k accuracy on PyCaffe during training phase?

73 Views Asked by At

I'd like to know if there's a way to get the top-k error on PyCaffe while doing training phase.

I know there's the top_k parameter for the .prototxt file but is there any way I can use it on PyCaffe?

layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "..."
  bottom: "label"
  top: "accuracy"
  accuracy_param {
    top_k: 5
  }
  include {
    phase: TEST
  }
}
1

There are 1 best solutions below

0
Ferran Noguera On BEST ANSWER

For anyone wondering I just find out you need to put multiple accuracy layers with different top-k numbers. Here is an example of a top-3 accuracy.

layer {
    name: "accuracy1"
    type: "Accuracy"
    bottom: "score"
    bottom: "label"
    top: "accuracy1"
    include {
      phase: TEST
    }
  }
  layer {
    name: "accuracy2"
    type: "Accuracy"
    bottom: "score"
    bottom: "label"
    top: "accuracy2"
    accuracy_param {
        top_k: 2
    }
    include {
      phase: TEST
    }
  }
  layer {
    name: "accuracy3"
    type: "Accuracy"
    bottom: "score"
    bottom: "label"
    top: "accuracy3"
    accuracy_param {
        top_k: 3
    }
    include {
      phase: TEST
    }
  }