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

Method processInput

samples/sampleAlgorithmSelector/sampleAlgorithmSelector.cpp:526–554  ·  view source on GitHub ↗

\brief Reads the input and mean data, preprocesses, and stores the result in a managed buffer.

Source from the content-addressed store, hash-verified

524//! \brief Reads the input and mean data, preprocesses, and stores the result in a managed buffer.
525//!
526bool SampleAlgorithmSelector::processInput(
527 samplesCommon::BufferManager const& buffers, std::string const& inputTensorName, int32_t inputFileIdx) const
528{
529
530 int32_t const inputH = mInputDims.d[2];
531 int32_t const inputW = mInputDims.d[3];
532
533 // Read a random digit file.
534 srand(unsigned(time(nullptr)));
535 std::vector<uint8_t> fileData(inputH * inputW);
536 readPGMFile(locateFile(std::to_string(inputFileIdx) + ".pgm", mParams.dataDirs), fileData.data(), inputH, inputW);
537
538 // Print ASCII representation of digit.
539 sample::gLogInfo << "Input:\n";
540 for (int32_t i = 0; i < inputH * inputW; i++)
541 {
542 sample::gLogInfo << (" .:-=+*#%@"[fileData[i] / 26]) << (((i + 1) % inputW) ? "" : "\n");
543 }
544 sample::gLogInfo << std::endl;
545
546 float* hostInputBuffer = static_cast<float*>(buffers.getHostBuffer(inputTensorName));
547
548 for (int32_t i = 0; i < inputH * inputW; i++)
549 {
550 hostInputBuffer[i] = 1.0F - static_cast<float>(fileData[i]) / 255.0F;
551 }
552
553 return true;
554}
555
556//!
557//! \brief Verifies that the output is correct and prints it.

Callers

nothing calls this directly

Calls 4

readPGMFileFunction · 0.85
locateFileFunction · 0.85
dataMethod · 0.45
getHostBufferMethod · 0.45

Tested by

no test coverage detected