Skip to content

Commit 12cd995

Browse files
authored
Added checks to ensure input, output quantization params are same. (#3056)
Added checks to ensure input, output quantization parameters are same. Without this check, pooling ops would silently ignore even if the IO quantization parameters are different. bug=fixes
1 parent bf42f03 commit 12cd995

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tensorflow/lite/micro/kernels/pooling_common.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ TfLiteStatus PoolingPrepare(TfLiteContext* context, TfLiteNode* node) {
6666
TF_LITE_ENSURE_STATUS(
6767
CalculateOpDataPooling(context, params, input, output, data));
6868

69+
// check if input, output quantization params are same.
70+
if (input->type == kTfLiteInt8 || input->type == kTfLiteInt16) {
71+
const double scale_diff = static_cast<double>(
72+
std::abs(input->params.scale - output->params.scale));
73+
TF_LITE_ENSURE(context, scale_diff <= 1.0e-6);
74+
TF_LITE_ENSURE(context,
75+
input->params.zero_point == output->params.zero_point);
76+
}
77+
6978
if (input->type == kTfLiteFloat32) {
7079
CalculateActivationRange(params->activation, &data->activation_min_f32,
7180
&data->activation_max_f32);

0 commit comments

Comments
 (0)