Return the top N predictions. */
| 103 | |
| 104 | /* Return the top N predictions. */ |
| 105 | std::vector<Prediction> Classifier::Classify(const cv::Mat& img, int N) { |
| 106 | std::vector<float> output = Predict(img); |
| 107 | |
| 108 | N = std::min<int>(labels_.size(), N); |
| 109 | std::vector<int> maxN = Argmax(output, N); |
| 110 | std::vector<Prediction> predictions; |
| 111 | for (int i = 0; i < N; ++i) { |
| 112 | int idx = maxN[i]; |
| 113 | predictions.push_back(std::make_pair(labels_[idx], output[idx])); |
| 114 | } |
| 115 | |
| 116 | return predictions; |
| 117 | } |
| 118 | |
| 119 | /* Load the mean file in binaryproto format. */ |
| 120 | void Classifier::SetMean(const string& mean_file) { |