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

Method run

test/op/ResizeTest.cpp:91–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89public:
90 virtual ~InterpTest() = default;
91 virtual bool run(int precision) {
92 auto input = _Input({1, 2, 2, 1}, NHWC);
93 input->setName("input_tensor");
94 // set input data
95 const float inpudata[] = {-1.0, -2.0, 3.0, 4.0};
96 auto inputPtr = input->writeMap<float>();
97 memcpy(inputPtr, inpudata, 4 * sizeof(float));
98 input->unMap();
99 input = _Convert(input, NC4HW4);
100
101 float hScale = 2.0;
102 float wScale = 2.0;
103 float scales[] = {1.0, 1.0, hScale, wScale};
104 auto scaleVar = _Const((void*)scales, {4}, NCHW);
105 int outW = int(wScale * 2);
106 int outH = int(hScale * 2);
107
108 //Interp Type:1
109 {
110 auto output = _Interp({input, scaleVar}, wScale, hScale, outW, outH, 1, false);
111 output = _Convert(output, NHWC);
112 const std::vector<float> expectedOutput = {-1.0, -1.0, -2.0, -2.0, -1.0, -1.0, -2.0, -2.0,
113 3.0, 3.0, 4.0, 4.0, 3.0, 3.0, 4.0, 4.0};
114 auto gotOutput = output->readMap<float>();
115
116 if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.01)) {
117 MNN_ERROR("InterpType:1 test failed!\n");
118 return false;
119 }
120
121 const std::vector<int> expectedDim = {1, 4, 4, 1};
122 auto gotDim = output->getInfo()->dim;
123 if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) {
124 MNN_ERROR("InterpType:1 test failed!\n");
125 return false;
126 }
127 }
128
129 //Interp Type:2
130 {
131 auto output = _Interp({input, scaleVar}, wScale, hScale, outW, outH, 2, false);
132 output = _Convert(output, NHWC);
133 const std::vector<float> expectedOutput = { -1.0000, -1.2500, -1.7500, -2.0000, 0.0000, -0.1250, -0.3750, -0.5000,
134 2.0000, 2.1250, 2.3750, 2.5000, 3.0000, 3.2500, 3.7500, 4.0000};
135 auto gotOutput = output->readMap<float>();
136 if (!checkVector<float>(gotOutput, expectedOutput.data(), 16, 0.01)) {
137 MNN_ERROR("InterpType:2 test failed!\n");
138 return false;
139 }
140
141 const std::vector<int> expectedDim = {1, 4, 4, 1};
142 auto gotDim = output->getInfo()->dim;
143 if (!checkVector<int>(gotDim.data(), expectedDim.data(), 4, 0)) {
144 MNN_ERROR("InterpType:2 test failed!\n");
145 return false;
146 }
147 }
148

Callers

nothing calls this directly

Calls 8

_InputFunction · 0.85
_ConvertFunction · 0.85
_ConstFunction · 0.85
_InterpFunction · 0.85
unMapMethod · 0.80
setNameMethod · 0.45
dataMethod · 0.45
getInfoMethod · 0.45

Tested by

no test coverage detected