| 172 | public: |
| 173 | virtual ~InterpInt8Test() = default; |
| 174 | virtual bool run(int precision) { |
| 175 | auto input = _Input({1, 2, 2, 1}, NHWC); |
| 176 | input->setName("input_tensor"); |
| 177 | input->writeScaleMap(0.032, 1.f); |
| 178 | // set input data |
| 179 | const float inpudata[] = {-1.0, -2.0, 3.0, 4.0}; |
| 180 | auto inputPtr = input->writeMap<float>(); |
| 181 | memcpy(inputPtr, inpudata, 4 * sizeof(float)); |
| 182 | input->unMap(); |
| 183 | input = _Convert(input, NC4HW4); |
| 184 | |
| 185 | float hScale = 2.0; |
| 186 | float wScale = 2.0; |
| 187 | float scales[] = {1.0, 1.0, hScale, wScale}; |
| 188 | auto scaleVar = _Const((void*)scales, {4}, NCHW); |
| 189 | int outW = int(wScale * 2); |
| 190 | int outH = int(hScale * 2); |
| 191 | |
| 192 | //Interp Type:1 |
| 193 | { |
| 194 | printf("InterpInt8 test: Type=1\n"); |
| 195 | auto output = _Interp({input, scaleVar}, wScale, hScale, outW, outH, 1, false); |
| 196 | output = _Convert(output, NHWC); |
| 197 | output->writeScaleMap(0.031372549, 0.f); |
| 198 | const std::vector<float> expectedOutput = {-1.0, -1.0, -2.0, -2.0, -1.0, -1.0, -2.0, -2.0, |
| 199 | 3.0, 3.0, 4.0, 4.0, 3.0, 3.0, 4.0, 4.0}; |
| 200 | auto gotOutput = output->readMap<float>(); |
| 201 | |
| 202 | if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.05)) { |
| 203 | MNN_ERROR("InterpInt8 ResizeType=1 :test failed!\n"); |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | const std::vector<int> expectedDim = {1, 4, 4, 1}; |
| 208 | auto gotDim = output->getInfo()->dim; |
| 209 | if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) { |
| 210 | MNN_ERROR("InterpInt8 ResizeType=1: test failed!\n"); |
| 211 | return false; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | //Interp Type:2 |
| 216 | { |
| 217 | printf("InterpInt8 test: Type=2\n"); |
| 218 | auto output = _Interp({input, scaleVar}, wScale, hScale, outW, outH, 2, false); |
| 219 | output = _Convert(output, NHWC); |
| 220 | output->writeScaleMap(0.031372549, 2.); |
| 221 | const std::vector<float> expectedOutput = { -1.0000, -1.2500, -1.7500, -2.0000, 0.0000, -0.1250, -0.3750, -0.5000, |
| 222 | 2.0000, 2.1250, 2.3750, 2.5000, 3.0000, 3.2500, 3.7500, 4.0000}; |
| 223 | auto gotOutput = output->readMap<float>(); |
| 224 | if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.05)) { |
| 225 | MNN_ERROR("InterpInt8 ResizeType=2 test failed!\n"); |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | const std::vector<int> expectedDim = {1, 4, 4, 1}; |
| 230 | auto gotDim = output->getInfo()->dim; |
| 231 | if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) { |