\brief Reads the digit map from file
| 463 | //! \brief Reads the digit map from file |
| 464 | //! |
| 465 | bool SampleIOFormats::readDigits(SampleBuffer& buffer, int32_t groundTruthDigit) |
| 466 | { |
| 467 | int32_t const inputH = buffer.dims.d[2]; |
| 468 | int32_t const inputW = buffer.dims.d[3]; |
| 469 | |
| 470 | // Read a random digit file |
| 471 | std::vector<uint8_t> fileData(inputH * inputW); |
| 472 | readPGMFile( |
| 473 | locateFile(std::to_string(groundTruthDigit) + ".pgm", mParams.dataDirs), fileData.data(), inputH, inputW); |
| 474 | |
| 475 | // Print ASCII representation of digit |
| 476 | for (int32_t i = 0; i < inputH * inputW; i++) |
| 477 | { |
| 478 | sample::gLogInfo << (" .:-=+*#%@"[fileData[i] / 26]) << (((i + 1) % inputW) ? "" : "\n"); |
| 479 | } |
| 480 | sample::gLogInfo << std::endl; |
| 481 | |
| 482 | float* inputBuf = reinterpret_cast<float*>(buffer.buffer); |
| 483 | |
| 484 | for (int32_t i = 0; i < inputH * inputW; i++) |
| 485 | { |
| 486 | inputBuf[i] = 1.0F - static_cast<float>(fileData[i] / 255.0F); |
| 487 | } |
| 488 | |
| 489 | return true; |
| 490 | } |
| 491 | |
| 492 | //! |
| 493 | //! \brief Verifies that the output is correct and prints it |
no test coverage detected