From 948fecfec9b1c4de16dc6a0c0bcd5edc2f566400 Mon Sep 17 00:00:00 2001 From: pinto0309 Date: Wed, 9 Aug 2023 09:47:12 +0900 Subject: [PATCH] Implemented a workaround to deal with the problem that padding with the minimum value causes the output error of `MaxPool2D` to be maximized only when quantizing with INT8 quantization. #444 --- README.md | 4 ++-- onnx2tf/__init__.py | 2 +- onnx2tf/onnx2tf.py | 1 + onnx2tf/ops/MaxPool.py | 8 +++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3fab0850..8e203265 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ Video speed is adjusted approximately 50 times slower than actual speed. $ docker run --rm -it \ -v `pwd`:/workdir \ -w /workdir \ - ghcr.io/pinto0309/onnx2tf:1.15.9 + ghcr.io/pinto0309/onnx2tf:1.15.10 or @@ -263,7 +263,7 @@ Video speed is adjusted approximately 50 times slower than actual speed. $ docker run --rm -it \ -v `pwd`:/workdir \ -w /workdir \ - docker.io/pinto0309/onnx2tf:1.15.9 + docker.io/pinto0309/onnx2tf:1.15.10 or diff --git a/onnx2tf/__init__.py b/onnx2tf/__init__.py index b8b07c9b..f3c98127 100644 --- a/onnx2tf/__init__.py +++ b/onnx2tf/__init__.py @@ -1,3 +1,3 @@ from onnx2tf.onnx2tf import convert, main -__version__ = '1.15.9' +__version__ = '1.15.10' diff --git a/onnx2tf/onnx2tf.py b/onnx2tf/onnx2tf.py index d987d973..b49853c7 100644 --- a/onnx2tf/onnx2tf.py +++ b/onnx2tf/onnx2tf.py @@ -765,6 +765,7 @@ def sanitizing(node): 'mvn_epsilon': mvn_epsilon, 'output_signaturedefs': output_signaturedefs, 'output_nms_with_dynamic_tensor': output_nms_with_dynamic_tensor, + 'output_integer_quantized_tflite': output_integer_quantized_tflite, 'use_cuda': use_cuda, } diff --git a/onnx2tf/ops/MaxPool.py b/onnx2tf/ops/MaxPool.py index a422bfee..fffc9977 100644 --- a/onnx2tf/ops/MaxPool.py +++ b/onnx2tf/ops/MaxPool.py @@ -65,6 +65,8 @@ def make_node( if isinstance(graph_node_input, gs.Variable) else graph_node_input input_tensor_shape = input_tensor.shape + output_integer_quantized_tflite = bool(kwargs['output_integer_quantized_tflite']) + # Pre-process transpose input_tensor = pre_process_transpose( value_before_transpose=input_tensor, @@ -221,11 +223,15 @@ def make_node( [[0, 0]] # use minimum limit value of data type for explicit padding value since this is max pooling + # https://github.com/PINTO0309/onnx2tf/issues/444 + # Implemented a workaround to deal with the problem that padding with the minimum value causes + # the output error of `MaxPool2D` to be maximized only when quantizing with INT8 quantization. padded_tensor = tf.pad( tensor=input_tensor, paddings=tf_pads, mode='CONSTANT', - constant_values=input_tensor.dtype.min + constant_values=input_tensor.dtype.min \ + if not output_integer_quantized_tflite else 0.0 ) else: