如何在训练阶段获得 PyCaffe 的 Top-k 准确性?

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

我想知道在训练阶段是否有办法在 PyCaffe 上获得 top-k 错误。

我知道 .prototxt 文件有 top_k 参数,但有什么方法可以在 PyCaffe 上使用它吗?

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

对于任何想知道我只是发现您需要放置具有不同 top-k 数字的精度层的人。这是前 3 准确度的示例。

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
    }
  }