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

Method processInput

samples/sampleOnnxMNIST/sampleOnnxMNIST.cpp:263–289  ·  view source on GitHub ↗

\brief Reads the input and stores the result in a managed buffer

Source from the content-addressed store, hash-verified

261//! \brief Reads the input and stores the result in a managed buffer
262//!
263bool SampleOnnxMNIST::processInput(const samplesCommon::BufferManager& buffers)
264{
265 const int inputH = mInputDims.d[2];
266 const int inputW = mInputDims.d[3];
267
268 // Read a random digit file
269 srand(unsigned(time(nullptr)));
270 std::vector<uint8_t> fileData(inputH * inputW);
271 mNumber = rand() % 10;
272 readPGMFile(locateFile(std::to_string(mNumber) + ".pgm", mParams.dataDirs), fileData.data(), inputH, inputW);
273
274 // Print an ascii representation
275 sample::gLogInfo << "Input:" << std::endl;
276 for (int i = 0; i < inputH * inputW; i++)
277 {
278 sample::gLogInfo << (" .:-=+*#%@"[fileData[i] / 26]) << (((i + 1) % inputW) ? "" : "\n");
279 }
280 sample::gLogInfo << std::endl;
281
282 float* hostDataBuffer = static_cast<float*>(buffers.getHostBuffer(mParams.inputTensorNames[0]));
283 for (int i = 0; i < inputH * inputW; i++)
284 {
285 hostDataBuffer[i] = 1.0 - float(fileData[i] / 255.0);
286 }
287
288 return true;
289}
290
291//!
292//! \brief Classifies digits and verify result

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