| 45 | class CloneNetTest : public MNNTestCase { |
| 46 | public: |
| 47 | virtual bool run(int precision) { |
| 48 | std::vector<float> inputData(channel * width * height); |
| 49 | for (int i = 0; i < channel * height * width; ++i){ |
| 50 | inputData[i] = (rand() % 10) * 0.1; |
| 51 | } |
| 52 | |
| 53 | MNN::BackendConfig config; |
| 54 | config.precision = (MNN::BackendConfig::PrecisionMode)MNN::BackendConfig::Precision_Normal; |
| 55 | config.memory = (MNN::BackendConfig::MemoryMode)MNN::BackendConfig::Memory_Normal; |
| 56 | std::shared_ptr<Executor> executor(Executor::newExecutor(getCurrentType(), config, 4)); |
| 57 | ExecutorScope scope(executor); |
| 58 | |
| 59 | auto net = _createModel(); |
| 60 | auto x = _Input({1, channel, height, width}, NCHW, halide_type_of<float>()); |
| 61 | { |
| 62 | auto xPtr = x->writeMap<float>(); |
| 63 | ::memcpy(xPtr, inputData.data(), channel * height * width * sizeof(float)); |
| 64 | x->unMap(); |
| 65 | } |
| 66 | |
| 67 | auto outputs = net->onForward({x}); |
| 68 | outputs[0] = _Convert(outputs[0], NC4HW4); |
| 69 | auto refPtr = outputs[0]->readMap<float>(); |
| 70 | auto size = outputs[0]->getInfo()->size; |
| 71 | |
| 72 | |
| 73 | // clone model |
| 74 | |
| 75 | std::unique_ptr<Module> tempModule(Module::clone(net.get())); |
| 76 | |
| 77 | auto xClone = _Input({1, channel, height, width}, NCHW, halide_type_of<float>()); |
| 78 | { |
| 79 | auto xPtr = xClone->writeMap<float>(); |
| 80 | ::memcpy(xPtr, inputData.data(), channel * height * width * sizeof(float)); |
| 81 | xClone->unMap(); |
| 82 | } |
| 83 | auto outputsClone = tempModule->onForward({xClone}); |
| 84 | outputsClone[0] = _Convert(outputsClone[0], NC4HW4); |
| 85 | auto outPtr = outputsClone[0]->readMap<float>(); |
| 86 | |
| 87 | for (int i = 0; i < size; ++i) { |
| 88 | float targetValue = refPtr[i], computeResult = outPtr[i]; |
| 89 | float diff = targetValue - computeResult; |
| 90 | if (fabsf(diff) > 0.001) { |
| 91 | MNN_PRINT("%d result Error: right=%f, error=%f\n", targetValue, computeResult); |
| 92 | return false; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | MNNTestSuiteRegister(CloneNetTest, "Clone/CloneNet"); |
nothing calls this directly
no test coverage detected