| 192 | } |
| 193 | |
| 194 | int 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 | } |
nothing calls this directly
no test coverage detected