| 45 | public: |
| 46 | virtual ~Interp2DTest() = default; |
| 47 | virtual bool run(int precision) { |
| 48 | auto input = _Input({2, 2}, NCHW); |
| 49 | input->setName("input_tensor"); |
| 50 | // set input data |
| 51 | const float inpudata[] = {-1.0, -2.0, 3.0, 4.0}; |
| 52 | auto inputPtr = input->writeMap<float>(); |
| 53 | memcpy(inputPtr, inpudata, 4 * sizeof(float)); |
| 54 | input->unMap(); |
| 55 | input = _Convert(input, NC4HW4); |
| 56 | |
| 57 | float hScale = 2.0; |
| 58 | float wScale = 2.0; |
| 59 | float scales[] = {hScale, wScale}; |
| 60 | auto scaleVar = _Const((void*)scales, {2}, NCHW); |
| 61 | int outW = int(wScale * 2); |
| 62 | int outH = int(hScale * 2); |
| 63 | |
| 64 | //Interp Type:1 |
| 65 | { |
| 66 | auto output = _Interp({input, scaleVar}, wScale, hScale, outW, outH, 1, false); |
| 67 | output = _Convert(output, NHWC); |
| 68 | const std::vector<float> expectedOutput = {-1.0, -1.0, -2.0, -2.0, -1.0, -1.0, -2.0, -2.0, |
| 69 | 3.0, 3.0, 4.0, 4.0, 3.0, 3.0, 4.0, 4.0}; |
| 70 | auto gotOutput = output->readMap<float>(); |
| 71 | |
| 72 | if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.01)) { |
| 73 | MNN_ERROR("Interp2D Type:1 test failed!\n"); |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | const std::vector<int> expectedDim = {4, 4}; |
| 78 | auto gotDim = output->getInfo()->dim; |
| 79 | if (!checkVector<int>(gotDim.data(), expectedDim.data(), 2, 0)) { |
| 80 | MNN_ERROR("Interp2D Type:1 test failed!\n"); |
| 81 | return false; |
| 82 | } |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | class InterpTest : public MNNTestCase { |