aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 }