\brief Checks whether the model prediction (in mOutput) is correct.
| 459 | //! \brief Checks whether the model prediction (in mOutput) is correct. |
| 460 | //! |
| 461 | bool SampleDynamicReshape::validateOutput(int digit) |
| 462 | { |
| 463 | const float* bufRaw = static_cast<const float*>(mOutput.hostBuffer.data()); |
| 464 | std::vector<float> prob(bufRaw, bufRaw + mOutput.hostBuffer.size()); |
| 465 | |
| 466 | int curIndex{0}; |
| 467 | for (const auto& elem : prob) |
| 468 | { |
| 469 | sample::gLogInfo << " Prob " << curIndex << " " << std::fixed << std::setw(5) << std::setprecision(4) << elem |
| 470 | << " " |
| 471 | << "Class " << curIndex << ": " << std::string(int(std::floor(elem * 10 + 0.5F)), '*') |
| 472 | << std::endl; |
| 473 | ++curIndex; |
| 474 | } |
| 475 | |
| 476 | int predictedDigit = std::max_element(prob.begin(), prob.end()) - prob.begin(); |
| 477 | return digit == predictedDigit; |
| 478 | } |
| 479 | |
| 480 | //! |
| 481 | //! \brief Initializes members of the params struct using the command line args |