\brief Reads the input and stores the result in a managed buffer
| 261 | //! \brief Reads the input and stores the result in a managed buffer |
| 262 | //! |
| 263 | bool 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 |
nothing calls this directly
no test coverage detected