// // ExprResizeComputeTest.cpp // MNNTests // // Created by MNN on 2019/09/10. // Copyright © 2018, Alibaba Group Holding Limited // #include #include "MNN_generated.h" #include "MNNTestSuite.h" #include "TestUtils.h" using namespace MNN::Express; class ExprResizeComputeTest : public MNNTestCase { public: virtual bool run(int precision) { { auto x = _Input({2, 16, 36, 39}, NC4HW4, halide_type_of()); auto sx = _Shape(x, true); auto wh = _StridedSlice(sx, _Unsqueeze(_Scalar(2), {0}), _Unsqueeze(_Scalar(4), {0}), _Unsqueeze(_Scalar(1), {0}), 0, 0, 0, 0, 0); wh = wh * _Scalar(2); auto y = _Interp({x, wh}, 0.0f, 0.0f, 0, 0, 1, true); auto yShape = y->getInfo(); if (yShape->dim[2] != 72 || yShape->dim[3] != 78) { return false; } { auto ptr = y->readMap(); if (nullptr != ptr) { FUNC_PRINT(1); return false; } } { x->writeMap(); auto ptr = y->readMap(); if (nullptr == ptr) { return false; } } x->resize({1, 16, 44, 45}); yShape = y->getInfo(); if (yShape->dim[2] != 88 || yShape->dim[3] != 90) { return false; } { x->writeMap(); auto ptr = y->readMap(); if (nullptr == ptr) { return false; } } } { auto x = _Input({2, 16, 36, 39}, NC4HW4, halide_type_of()); auto whi = _Input({2}, NHWC, halide_type_of()); auto whPtr = whi->writeMap(); whPtr[0] = 66; whPtr[1] = 77; auto wh = whi * _Scalar(2); auto y = _Interp({x, wh}, 0.0f, 0.0f, 0, 0, 1, true); auto yShape = y->getInfo(); if (yShape->dim[2] != 66 * 2 || yShape->dim[3] != 77 * 2) { return false; } { x->writeMap(); auto ptr = y->readMap(); if (nullptr == ptr) { return false; } } whPtr = whi->writeMap(); whPtr[0] = 11; whPtr[1] = 22; yShape = y->getInfo(); if (yShape->dim[2] != 11 * 2 || yShape->dim[3] != 22 * 2) { return false; } { x->writeMap(); auto ptr = y->readMap(); if (nullptr == ptr) { return false; } } } { auto x = _Input({1, 2, 3, 4, 5}, NCHW, halide_type_of()); auto inputPtr = x->writeMap(); for (int i = 0; i < x->getInfo()->size; ++i) { inputPtr[i] = (float)i; } x->unMap(); std::unique_ptr interp(new MNN::InterpT); interp->resizeType = 1; interp->widthScale = 2.0f; interp->heightScale = 2.0f; interp->depthScale = 2.0f; std::unique_ptr op(new MNN::OpT); op->type = MNN::OpType_Interp3D; op->main.type = MNN::OpParameter_Interp; op->main.value = interp.release(); auto y = Variable::create(Expr::create(op.get(), {x})); auto yShape = y->getInfo(); if (yShape == nullptr) { return false; } const std::vector expectedDim = {1, 2, 6, 8, 10}; if (!checkVector(yShape->dim.data(), expectedDim.data(), 5, 0)) { return false; } if (nullptr == y->readMap()) { return false; } } return true; } }; MNNTestSuiteRegister(ExprResizeComputeTest, "expr/ExprResizeCompute");