From 7e78f949aa43b1a3ce1ebbaf4fe033a69fcd92ed Mon Sep 17 00:00:00 2001 From: Yvonne Chen Date: Fri, 24 Dec 2021 12:30:44 +0100 Subject: [PATCH] fix depthwise conv quantize compute weight scale>1 algorithm --- src/caffe/util/math_functions.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/caffe/util/math_functions.cpp b/src/caffe/util/math_functions.cpp index d793f06a..130f1415 100644 --- a/src/caffe/util/math_functions.cpp +++ b/src/caffe/util/math_functions.cpp @@ -559,7 +559,11 @@ void MultiplyByQuantizedMultiplierVR(const int n, Dtype* x, const int mul, const } } else if (round_mode == 2) { for(int i = 0; i < n; ++i) { - x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul((int)x[i], mul), shf); + // ref see https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/internal/common.h#L251 + int left_shift = shift > 0 ? shift : 0; + int right_shift = shift > 0 ? 0 : -shift; + x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul(int(x[i]) * + (1 << left_shift), mul), right_shift); } } }