| 82 | } |
| 83 | |
| 84 | std::unique_ptr<float> RGBImageReader::process() const |
| 85 | { |
| 86 | const int C = mDims.d[1]; |
| 87 | const int H = mDims.d[2]; |
| 88 | const int W = mDims.d[3]; |
| 89 | auto buffer = std::unique_ptr<float>{new float[volume()]}; |
| 90 | |
| 91 | if (mPPM.h == H && mPPM.w == W) |
| 92 | { |
| 93 | for (int c = 0; c < C; c++) |
| 94 | { |
| 95 | for (int j = 0, HW = H * W; j < HW; ++j) |
| 96 | { |
| 97 | buffer.get()[c * HW + j] = (static_cast<float>(mPPM.buffer[j * C + c])/mPPM.max - mMean[c]) / mStd[c]; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | assert(!"Specified dimensions don't match PPM image"); |
| 104 | } |
| 105 | |
| 106 | return buffer; |
| 107 | } |
| 108 | |
| 109 | ArgmaxImageWriter::ArgmaxImageWriter(const std::string& filename, const nvinfer1::Dims& dims, const std::vector<int>& palette, const int num_classes) |
| 110 | : ImageBase(filename, dims) |