get classification result from network output
| 73 | |
| 74 | // get classification result from network output |
| 75 | int32_t GetClassificationResult(const float* scores, const int32_t size) { |
| 76 | vector<pair<float, int>> pairs(size); |
| 77 | for (int32_t i = 0; i < size; i++) { |
| 78 | pairs[i] = make_pair(scores[i], i); |
| 79 | } |
| 80 | |
| 81 | auto cmp_func = [](const pair<float, int>& p0, const pair<float, int>& p1) -> bool { |
| 82 | return p0.first > p1.first; |
| 83 | }; |
| 84 | |
| 85 | const int32_t top_k = 5; |
| 86 | nth_element(pairs.begin(), pairs.begin() + top_k, pairs.end(), cmp_func); // get top K results & sort |
| 87 | sort(pairs.begin(), pairs.begin() + top_k, cmp_func); |
| 88 | |
| 89 | printf("top %d results:\n", top_k); |
| 90 | for (int32_t i = 0; i < top_k; ++i) { |
| 91 | printf("%dth: %-10f %-10d %s\n", i + 1, pairs[i].first, pairs[i].second, imagenet_labels_tab[pairs[i].second]); |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | // run classification model |
| 98 | int RunClassificationModel(const Mat& src_img, const char* onnx_model_path) { |
no test coverage detected