MCPcopy Create free account
hub / github.com/alibaba/MNN / run

Method run

test/clone/CloneNetTest.cpp:47–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45class CloneNetTest : public MNNTestCase {
46public:
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
100MNNTestSuiteRegister(CloneNetTest, "Clone/CloneNet");

Callers

nothing calls this directly

Calls 11

randFunction · 0.85
getCurrentTypeFunction · 0.85
_InputFunction · 0.85
_ConvertFunction · 0.85
unMapMethod · 0.80
_createModelFunction · 0.70
cloneFunction · 0.50
dataMethod · 0.45
onForwardMethod · 0.45
getInfoMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected