MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / verifyOutput

Method verifyOutput

samples/sampleAlgorithmSelector/sampleAlgorithmSelector.cpp:559–589  ·  view source on GitHub ↗

\brief Verifies that the output is correct and prints it.

Source from the content-addressed store, hash-verified

557//! \brief Verifies that the output is correct and prints it.
558//!
559bool SampleAlgorithmSelector::verifyOutput(
560 samplesCommon::BufferManager const& buffers, std::string const& outputTensorName, int32_t groundTruthDigit) const
561{
562 float* prob = static_cast<float*>(buffers.getHostBuffer(outputTensorName));
563 int32_t constexpr kDIGITS = 10;
564
565 std::for_each(prob, prob + kDIGITS, [](float& n) { n = exp(n); });
566
567 float const sum = std::accumulate(prob, prob + kDIGITS, 0.F);
568
569 std::for_each(prob, prob + kDIGITS, [sum](float& n) { n = n / sum; });
570
571 auto max_ele = std::max_element(prob, prob + kDIGITS);
572
573 float const val = *max_ele;
574
575 int32_t const idx = max_ele - prob;
576
577 // Print histogram of the output probability distribution.
578 sample::gLogInfo << "Output:\n";
579 for (int32_t i = 0; i < kDIGITS; i++)
580 {
581 sample::gLogInfo << " Prob " << i << " " << std::fixed << std::setw(5) << std::setprecision(4) << prob[i]
582 << " "
583 << "Class " << i << ": " << std::string(int32_t(std::floor(prob[i] * 10 + 0.5F)), '*')
584 << std::endl;
585 }
586 sample::gLogInfo << std::endl;
587
588 return (idx == groundTruthDigit && val > 0.9F);
589}
590
591//!
592//! \brief Uses an ONNX parser to create the MNIST Network and marks the

Callers

nothing calls this directly

Calls 3

expFunction · 0.50
floorFunction · 0.50
getHostBufferMethod · 0.45

Tested by

no test coverage detected