| 1129 | class ResizeOptimizationTest : public MNNTestCase { |
| 1130 | public: |
| 1131 | virtual bool run(int precision) { |
| 1132 | std::vector<int8_t> buffer; |
| 1133 | { |
| 1134 | // Make Buffer |
| 1135 | auto x0 = _Input({1, 3, 32, 32}, NCHW, halide_type_of<float>()); |
| 1136 | x0->setName("x0"); |
| 1137 | { |
| 1138 | auto x1s = _Shape(x0); |
| 1139 | auto ss = _Unstack(x1s); |
| 1140 | auto w = ss[2]; |
| 1141 | auto h = ss[3]; |
| 1142 | int batchNumber = 1; |
| 1143 | int channelNumber = 3; |
| 1144 | auto batch = _Const(&batchNumber, {}, NCHW, halide_type_of<int32_t>()); |
| 1145 | auto channel = _Const(&channelNumber, {}, NCHW, halide_type_of<int32_t>()); |
| 1146 | x0 = _Reshape(x0, _Stack({batch * channel, w * h})); |
| 1147 | x0 = _Reshape(x0, x1s); |
| 1148 | } |
| 1149 | auto y0 = _mobileNetV1Expr(_Convert(x0, NC4HW4), false); |
| 1150 | y0->setName("y0"); |
| 1151 | auto x1 = _Input({1, 3, 64, 64}, NCHW, halide_type_of<float>()); |
| 1152 | x1->setName("x1"); |
| 1153 | auto y1 = _mobileNetV1Expr(_Convert(x1, NC4HW4), false); |
| 1154 | y1->setName("y1"); |
| 1155 | auto z = y0 + y1; |
| 1156 | z->setName("z"); |
| 1157 | buffer = Variable::save({z}); |
| 1158 | } |
| 1159 | std::vector<std::pair<std::vector<int>, std::vector<int>>> inputShapes { |
| 1160 | {{1, 3, 32, 32}, {1, 3, 24, 24}}, |
| 1161 | {{1, 3, 16, 16}, {1, 3, 24, 24}}, |
| 1162 | {{1, 3, 48, 48}, {1, 3, 24, 24}}, |
| 1163 | }; |
| 1164 | { |
| 1165 | // Test For Interpreter API |
| 1166 | std::shared_ptr<Interpreter> net(Interpreter::createFromBuffer((void*)buffer.data(), buffer.size()), Interpreter::destroy); |
| 1167 | ScheduleConfig config; |
| 1168 | config.numThread = 1; |
| 1169 | net->setSessionMode(Interpreter::Session_Debug); |
| 1170 | auto session = net->createSession(config); |
| 1171 | auto getResult = [session, net, &inputShapes] { |
| 1172 | std::vector<float> resultSummer(inputShapes.size()); |
| 1173 | auto x0 = net->getSessionInput(session, "x0"); |
| 1174 | auto x1 = net->getSessionInput(session, "x1"); |
| 1175 | auto z = net->getSessionOutput(session, "z"); |
| 1176 | auto fillInput = [](MNN::Tensor* t, float v) { |
| 1177 | std::shared_ptr<MNN::Tensor> tensor(new MNN::Tensor(t, t->getDimensionType())); |
| 1178 | auto size = tensor->elementSize(); |
| 1179 | auto ptr = tensor->host<float>(); |
| 1180 | float cv = v; |
| 1181 | for (int i=0; i<size; ++i) { |
| 1182 | ptr[i] = cv; |
| 1183 | cv = cv * -1.0f; |
| 1184 | } |
| 1185 | t->copyFromHostTensor(tensor.get()); |
| 1186 | }; |
| 1187 | for (int u=0; u<inputShapes.size(); ++u) { |
| 1188 | net->resizeTensor(x0, inputShapes[u].first); |
nothing calls this directly
no test coverage detected