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

Method verifyOutput

samples/sampleOnnxMNIST/sampleOnnxMNIST.cpp:296–329  ·  view source on GitHub ↗

\brief Classifies digits and verify result \return whether the classification output matches expectations

Source from the content-addressed store, hash-verified

294//! \return whether the classification output matches expectations
295//!
296bool SampleOnnxMNIST::verifyOutput(const samplesCommon::BufferManager& buffers)
297{
298 const int outputSize = mOutputDims.d[1];
299 float* output = static_cast<float*>(buffers.getHostBuffer(mParams.outputTensorNames[0]));
300 float val{0.0F};
301 int idx{0};
302
303 // Calculate Softmax
304 float sum{0.0F};
305 for (int i = 0; i < outputSize; i++)
306 {
307 output[i] = exp(output[i]);
308 sum += output[i];
309 }
310
311 sample::gLogInfo << "Output:" << std::endl;
312 for (int i = 0; i < outputSize; i++)
313 {
314 output[i] /= sum;
315 val = std::max(val, output[i]);
316 if (val == output[i])
317 {
318 idx = i;
319 }
320
321 sample::gLogInfo << " Prob " << i << " " << std::fixed << std::setw(5) << std::setprecision(4) << output[i]
322 << " "
323 << "Class " << i << ": " << std::string(int(std::floor(output[i] * 10 + 0.5F)), '*')
324 << std::endl;
325 }
326 sample::gLogInfo << std::endl;
327
328 return idx == mNumber && val > 0.9F;
329}
330
331//!
332//! \brief Initializes members of the params struct using the command line args

Callers

nothing calls this directly

Calls 4

maxFunction · 0.85
expFunction · 0.50
floorFunction · 0.50
getHostBufferMethod · 0.45

Tested by

no test coverage detected