| 29 | } |
| 30 | |
| 31 | Int8EntropyCalibrator2::Int8EntropyCalibrator2(int32_t batchSize, int32_t inputW, int32_t inputH, const std::string &calibDataDirPath, |
| 32 | const std::string &calibTableName, const std::string &inputBlobName, |
| 33 | const std::array<float, 3> &subVals, const std::array<float, 3> &divVals, bool normalize, |
| 34 | bool readCache) |
| 35 | : m_batchSize(batchSize), m_inputW(inputW), m_inputH(inputH), m_imgIdx(0), m_calibTableName(calibTableName), |
| 36 | m_inputBlobName(inputBlobName), m_subVals(subVals), m_divVals(divVals), m_normalize(normalize), m_readCache(readCache) { |
| 37 | |
| 38 | // Allocate GPU memory to hold the entire batch |
| 39 | m_inputCount = 3 * inputW * inputH * batchSize; |
| 40 | checkCudaErrorCode(cudaMalloc(&m_deviceInput, m_inputCount * sizeof(float))); |
| 41 | |
| 42 | // Read the name of all the files in the specified directory. |
| 43 | if (!doesFileExist(calibDataDirPath)) { |
| 44 | throw std::runtime_error("Error, directory at provided path does not exist: " + calibDataDirPath); |
| 45 | } |
| 46 | |
| 47 | m_imgPaths = getFilesInDirectory(calibDataDirPath); |
| 48 | if (m_imgPaths.size() < static_cast<size_t>(batchSize)) { |
| 49 | throw std::runtime_error("There are fewer calibration images than the specified batch size!"); |
| 50 | } |
| 51 | |
| 52 | // Randomize the calibration data |
| 53 | auto rd = std::random_device{}; |
| 54 | auto rng = std::default_random_engine{rd()}; |
| 55 | std::shuffle(std::begin(m_imgPaths), std::end(m_imgPaths), rng); |
| 56 | } |
| 57 | |
| 58 | int32_t Int8EntropyCalibrator2::getBatchSize() const noexcept { |
| 59 | // Return the batch size |
nothing calls this directly
no test coverage detected