Skip to content

Commit

Permalink
Implemented a workaround to deal with the problem that padding with t…
Browse files Browse the repository at this point in the history
…he minimum value causes the output error of `MaxPool2D` to be maximized only when quantizing with INT8 quantization. #444
  • Loading branch information
PINTO0309 committed Aug 9, 2023
1 parent 32534d7 commit 948fecf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ 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

# Authentication is not required for pulls from Docker Hub.
$ docker run --rm -it \
-v `pwd`:/workdir \
-w /workdir \
docker.io/pinto0309/onnx2tf:1.15.9
docker.io/pinto0309/onnx2tf:1.15.10

or

Expand Down
2 changes: 1 addition & 1 deletion onnx2tf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from onnx2tf.onnx2tf import convert, main

__version__ = '1.15.9'
__version__ = '1.15.10'
1 change: 1 addition & 0 deletions onnx2tf/onnx2tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
8 changes: 7 additions & 1 deletion onnx2tf/ops/MaxPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 948fecf

Please sign in to comment.