| 137 | } |
| 138 | |
| 139 | static int PrintTopLabels(const vector<TF_Tensor*>& outputs, const char* labels_file) |
| 140 | { |
| 141 | vector<string> labels; |
| 142 | int read_labels_status = ReadLabelsFile(labels_file, &labels); |
| 143 | if(read_labels_status < 0) |
| 144 | return -1; |
| 145 | |
| 146 | int label_count = labels.size(); |
| 147 | int N = std::min<int>(label_count, 5); |
| 148 | |
| 149 | float* data = ( float* )TF_TensorData(outputs[0]); |
| 150 | |
| 151 | vector<pair<int, float>> scores; |
| 152 | for(int i = 0; i < label_count; i++) |
| 153 | { |
| 154 | scores.push_back(pair<int, float>({i, data[i]})); |
| 155 | } |
| 156 | |
| 157 | sort(scores.begin(), scores.end(), |
| 158 | [](const pair<int, float>& left, const pair<int, float>& right) { return left.second > right.second; }); |
| 159 | |
| 160 | for(int pos = 0; pos < N; pos++) |
| 161 | { |
| 162 | const int label_index = scores[pos].first; |
| 163 | const float score = scores[pos].second; |
| 164 | cout << std::fixed << std::setprecision(4) << score << " - \"" << labels[label_index] << "\"" << endl; |
| 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /* To make tensor release happy...*/ |
| 170 | static void dummy_deallocator(void* data, size_t len, void* arg) {} |
no test coverage detected