aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Zhao2019-08-28 16:28:18 -0500
committerYuan Zhao2019-08-28 16:28:18 -0500
commit8d4329d8ee7f118bb8eab859e67ba61ea9144fa8 (patch)
tree0bd04d6182f6840d358eac51a934aeb469e0ecf0
parentc0aaf795d8f486a7d46b23a64b36f6b01d924161 (diff)
downloadtidl-api-8d4329d8ee7f118bb8eab859e67ba61ea9144fa8.tar.gz
tidl-api-8d4329d8ee7f118bb8eab859e67ba61ea9144fa8.tar.xz
tidl-api-8d4329d8ee7f118bb8eab859e67ba61ea9144fa8.zip
Print out imagenet object index in imagenet example
- The object index is helpful information, in addition to text label that has already been printed out. - Offset tensorflow model output by 1 to remove backgroup index - MCT-1216
-rw-r--r--examples/imagenet/main.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/examples/imagenet/main.cpp b/examples/imagenet/main.cpp
index dc1035b..6aa7155 100644
--- a/examples/imagenet/main.cpp
+++ b/examples/imagenet/main.cpp
@@ -306,6 +306,10 @@ bool WriteFrameOutput(const ExecutionObjectPipeline &eop,
306 const int k = 5; 306 const int k = 5;
307 unsigned char *out = (unsigned char *) eop.GetOutputBufferPtr(); 307 unsigned char *out = (unsigned char *) eop.GetOutputBufferPtr();
308 int out_size = eop.GetOutputBufferSizeInBytes(); 308 int out_size = eop.GetOutputBufferSizeInBytes();
309 // Tensorflow trained network outputs 1001 probabilities,
310 // with 0-index being background, thus we need to subtract 1 when
311 // reporting classified object from 1000 categories
312 int background_offset = out_size == 1001 ? 1 : 0;
309 313
310 // sort and get k largest values and corresponding indices 314 // sort and get k largest values and corresponding indices
311 typedef pair<unsigned char, int> val_index; 315 typedef pair<unsigned char, int> val_index;
@@ -338,8 +342,9 @@ bool WriteFrameOutput(const ExecutionObjectPipeline &eop,
338 for (int i = k - 1; i >= 0; i--) 342 for (int i = k - 1; i >= 0; i--)
339 { 343 {
340 if (sorted[i].first * 100 < min_prob_255) break; 344 if (sorted[i].first * 100 < min_prob_255) break;
341 cout << k-i << ": " 345 int imagenet_index = sorted[i].second - background_offset;
342 << object_classes->At(sorted[i].second).label 346 cout << k-i << ": [" << imagenet_index << "] "
347 << object_classes->At(imagenet_index).label
343 << ", prob = " << setprecision(4) 348 << ", prob = " << setprecision(4)
344 << ((sorted[i].first * 100) / 255.0f) << "%" << endl; 349 << ((sorted[i].first * 100) / 255.0f) << "%" << endl;
345 } 350 }