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

Function QuantizeDepthwiseConv

tools/quantization/quantizeWeight.cpp:194–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194int QuantizeDepthwiseConv(const float* weight, const int size, const float* bias, int8_t* quantizedWeight,
195 int32_t* quantizedBias, float* scale, const float inputScale, const float outputScale,
196 const int inputChannel, const int outputChannel, std::string method, float weightClampValue, bool mergeChannel) {
197 DCHECK(inputChannel == outputChannel) << "Input Data Size Error!";
198
199 std::vector<float> quantizedWeightScale(inputChannel);
200 if (method == "MAX_ABS") {
201 SymmetricQuantizeWeight(weight, size, quantizedWeight, quantizedWeightScale.data(), inputChannel, weightClampValue);
202 }
203 else if (method == "ADMM") {
204 QuantizeWeightADMM(weight, size, quantizedWeight, quantizedWeightScale.data(), inputChannel, weightClampValue);
205 }
206
207 for (int c = 0; c < inputChannel; ++c) {
208 const int index = c;
209 if (fabs(outputScale) <= 1e-6) {
210 scale[index] = 0.0f;
211 } else {
212 scale[index] = inputScale * quantizedWeightScale[c] / outputScale;
213 }
214 }
215
216 if (bias) {
217 for (int i = 0; i < outputChannel; ++i) {
218 if (fabs(inputScale) <= 1e-6 || fabs(quantizedWeightScale[i]) <= 1e-6) {
219 quantizedBias[i] = 0;
220 } else {
221 quantizedBias[i] = static_cast<int32_t>(bias[i] / (inputScale * quantizedWeightScale[i]));
222 }
223 }
224 }
225
226 return 0;
227}

Callers

nothing calls this directly

Calls 4

QuantizeWeightADMMFunction · 0.85
fabsFunction · 0.85
SymmetricQuantizeWeightFunction · 0.70
dataMethod · 0.45

Tested by

no test coverage detected