Skip to content

Commit 7e78f94

Browse files
committed
fix depthwise conv quantize compute weight scale>1 algorithm
1 parent d2dfb1d commit 7e78f94

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/caffe/util/math_functions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ void MultiplyByQuantizedMultiplierVR(const int n, Dtype* x, const int mul, const
559559
}
560560
} else if (round_mode == 2) {
561561
for(int i = 0; i < n; ++i) {
562-
x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul((int)x[i], mul), shf);
562+
// ref see https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/internal/common.h#L251
563+
int left_shift = shift > 0 ? shift : 0;
564+
int right_shift = shift > 0 ? 0 : -shift;
565+
x[i] = tfl_RoundingDivideByPOT(tfl_SaturatingRoundingDoublingHighMul(int(x[i]) *
566+
(1 << left_shift), mul), right_shift);
563567
}
564568
}
565569
}

0 commit comments

Comments
 (0)