Return the indices of the top N values of vector v. */
| 90 | |
| 91 | /* Return the indices of the top N values of vector v. */ |
| 92 | static std::vector<int> Argmax(const std::vector<float>& v, int N) { |
| 93 | std::vector<std::pair<float, int> > pairs; |
| 94 | for (size_t i = 0; i < v.size(); ++i) |
| 95 | pairs.push_back(std::make_pair(v[i], i)); |
| 96 | std::partial_sort(pairs.begin(), pairs.begin() + N, pairs.end(), PairCompare); |
| 97 | |
| 98 | std::vector<int> result; |
| 99 | for (int i = 0; i < N; ++i) |
| 100 | result.push_back(pairs[i].second); |
| 101 | return result; |
| 102 | } |
| 103 | |
| 104 | /* Return the top N predictions. */ |
| 105 | std::vector<Prediction> Classifier::Classify(const cv::Mat& img, int N) { |