MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PrintTopLabels

Function PrintTopLabels

tensorflow/contrib/pi_examples/camera/camera.cc:308–327  ·  view source on GitHub ↗

Given the output of a model run, and the name of a file containing the labels this prints out the top five highest-scoring values.

Source from the content-addressed store, hash-verified

306// Given the output of a model run, and the name of a file containing the labels
307// this prints out the top five highest-scoring values.
308Status PrintTopLabels(const std::vector<Tensor>& outputs,
309 const std::vector<string>& labels, int label_count,
310 float print_threshold) {
311 const int how_many_labels = std::min(5, static_cast<int>(label_count));
312 Tensor indices;
313 Tensor scores;
314 TF_RETURN_IF_ERROR(GetTopLabels(outputs, how_many_labels, &indices, &scores));
315 tensorflow::TTypes<float>::Flat scores_flat = scores.flat<float>();
316 tensorflow::TTypes<int32>::Flat indices_flat = indices.flat<int32>();
317 for (int pos = 0; pos < how_many_labels; ++pos) {
318 const int label_index = indices_flat(pos);
319 const float score = scores_flat(pos);
320 LOG(INFO) << labels[label_index] << " (" << label_index << "): " << score;
321 // Print the top label to stdout if it's above a threshold.
322 if ((pos == 0) && (score > print_threshold)) {
323 std::cout << labels[label_index] << std::endl;
324 }
325 }
326 return Status::OK();
327}
328
329// Given an image buffer, resize it to the requested size, and then scale the
330// values as desired.

Callers 1

mainFunction · 0.70

Calls 2

GetTopLabelsFunction · 0.70
minFunction · 0.50

Tested by

no test coverage detected