summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c0aaf79)
raw | patch | inline | side by side (parent: c0aaf79)
author | Yuan Zhao <yuanzhao@ti.com> | |
Wed, 28 Aug 2019 21:28:18 +0000 (16:28 -0500) | ||
committer | Yuan Zhao <yuanzhao@ti.com> | |
Wed, 28 Aug 2019 21:28:18 +0000 (16:28 -0500) |
- 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
that has already been printed out.
- Offset tensorflow model output by 1 to remove backgroup index
- MCT-1216
examples/imagenet/main.cpp | patch | blob | history |
index dc1035be9442a76b567bb994be12c1e6ace5e632..6aa7155a03c1e44c32c31032ea9a52b07463e64f 100644 (file)
const int k = 5;
unsigned char *out = (unsigned char *) eop.GetOutputBufferPtr();
int out_size = eop.GetOutputBufferSizeInBytes();
+ // Tensorflow trained network outputs 1001 probabilities,
+ // with 0-index being background, thus we need to subtract 1 when
+ // reporting classified object from 1000 categories
+ int background_offset = out_size == 1001 ? 1 : 0;
// sort and get k largest values and corresponding indices
typedef pair<unsigned char, int> val_index;
for (int i = k - 1; i >= 0; i--)
{
if (sorted[i].first * 100 < min_prob_255) break;
- cout << k-i << ": "
- << object_classes->At(sorted[i].second).label
+ int imagenet_index = sorted[i].second - background_offset;
+ cout << k-i << ": [" << imagenet_index << "] "
+ << object_classes->At(imagenet_index).label
<< ", prob = " << setprecision(4)
<< ((sorted[i].first * 100) / 255.0f) << "%" << endl;
}