BVLC/caffe — pull request #531 by robwhess (2014-06-24 00:23:21+00:00)
Title: Top-k accuracy

Note: sorry to not have used the typical pull-request-first-then-develop approach. We had already developed this code and thought it might be a useful contribution back to the main repo.

This pull request generalizes the accuracy layer to compute the top-k accuracy instead of the top-1 accuracy. Specifically, a testing example can now be counted as a correct classification if its true label falls within the top k predicted labels. This will be useful, for example, in comparing results to ImageNet benchmarks, which are typically reported as top-5 accuracy/error.

To use, add to your network proto an `ACCURACY` layer with an `accuracy_param` (new) with a `top_k` element. For example:
```
...
layers {
name: "accuracy"
type: ACCURACY
bottom: "prob"
bottom: "label"
top: "accuracy"
accuracy_param {
top_k: 5;
}
}
```
The default value for `top_k` is 1, which replicates the current behavior under `dev` (i.e. this update is backwards-compatible with previous versions).