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

Method test

test/op/DeconvolutionTest.cpp:126–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125protected:
126 static bool test(const std::string& test_op_name,
127 int batch, int ic, int oc, int ih, int iw, int pad_h, int pad_w, int kh,
128 int kw, int stride, int dilation, int group, int precision) {
129 int ow = (iw - 1) * stride + dilation * (kw - 1) + 1 - pad_w * 2;
130 int oh = (ih - 1) * stride + dilation * (kh - 1) + 1 - pad_h * 2;
131 if (ow <=0 || oh <= 0) {
132 return true;
133 }
134 auto input = _Input({batch, ic, ih, iw}, NCHW, halide_type_of<float>());
135 auto inputPtr = input->writeMap<float>();
136 {
137 int size = input->getInfo()->size;
138 for (int i=0; i<size; ++i) {
139 inputPtr[i] = (float)((i+1) % 10) / 100.0f;
140 }
141 }
142 std::vector<float> weightData(ic*oc*kh*kw);
143 for (int i=0; i<weightData.size(); ++i) {
144 weightData[i] = (float)(10-(i%10)) / 10.0f;
145 }
146 std::vector<float> biasData(oc);
147 for (int i=0; i<oc; ++i) {
148 biasData[i] = (float)(5-(i%10)) / 10.0f;
149 }
150 std::vector<float> rightOutData;
151 reference_deconv2d(inputPtr, weightData, biasData, rightOutData, batch, ic, oc, ih, iw, pad_h, pad_w, kh, kw, stride, stride, dilation);
152 input = _Convert(input, NC4HW4);
153 auto output = _Deconv(std::move(weightData), std::move(biasData), input, {ic, oc}, {kw, kh}, VALID,
154 {stride, stride}, {dilation, dilation}, group, {pad_w, pad_h}, false, false);
155 output = _Convert(output, NCHW);
156 if (rightOutData.size() != output->getInfo()->size) {
157 FUNC_PRINT(1);
158 return false;
159 }
160
161
162 // difference below 0.5% relative error is considered correct.
163 auto outputPtr = output->readMap<float>();
164 float errorScale = precision <= MNN::BackendConfig::Precision_High ? 1 : 20;
165 if (!checkVectorByRelativeError<float>(outputPtr, rightOutData.data(), rightOutData.size(), 0.005 * errorScale)) {
166 MNN_ERROR("%s test failed!\n", test_op_name.c_str());
167 return false;
168 }
169 return true;
170 }
171 static bool test(const std::string& test_op_name,
172 vector<float>& inputData, vector<float>& weightData, vector<float>& biasData, vector<float>& rightOutData,
173 int batch, int ic, int oc, int ih, int iw, PadMode mode, int pad_h, int pad_w, int kh,

Callers

nothing calls this directly

Calls 8

_InputFunction · 0.85
reference_deconv2dFunction · 0.85
_ConvertFunction · 0.85
_DeconvFunction · 0.70
getInfoMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected