From 9ad39783dace4b9968637fc1aebb5c2dc3651fff Mon Sep 17 00:00:00 2001 From: pinto0309 Date: Sun, 1 Sep 2024 19:20:53 +0900 Subject: [PATCH] Fixed a bug in the optimization process for arithmetic operations --- README.md | 4 ++-- onnx2tf/__init__.py | 2 +- onnx2tf/utils/common_functions.py | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4b7bd46..de3ff3e0 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,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.25.8 + ghcr.io/pinto0309/onnx2tf:1.25.9 or @@ -307,7 +307,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.25.8 + docker.io/pinto0309/onnx2tf:1.25.9 or diff --git a/onnx2tf/__init__.py b/onnx2tf/__init__.py index b8d9e019..bea18152 100644 --- a/onnx2tf/__init__.py +++ b/onnx2tf/__init__.py @@ -1,3 +1,3 @@ from onnx2tf.onnx2tf import convert, main -__version__ = '1.25.8' +__version__ = '1.25.9' diff --git a/onnx2tf/utils/common_functions.py b/onnx2tf/utils/common_functions.py index 5a1b9ba6..458acf81 100644 --- a/onnx2tf/utils/common_functions.py +++ b/onnx2tf/utils/common_functions.py @@ -5202,7 +5202,19 @@ def merge_two_consecutive_identical_ops_into_one( tf_type = tf.math.divide elif tf_func == 'Sub': - if ( + if isinstance(input_tensor_1, np.ndarray) or hasattr(input_tensor_1, 'numpy'): + tf_layers_dict[graph_node_output.name]['tf_node'] = \ + tf.math.subtract( + x=input_tensor_1 \ + if not isinstance(input_tensor_1, np.ndarray) \ + else tf.convert_to_tensor(input_tensor_1), + y=input_tensor_2 \ + if not isinstance(input_tensor_2, np.ndarray) \ + else tf.convert_to_tensor(input_tensor_2), + name=graph_node.name, + ) + tf_type = tf.math.subtract + elif ( not isinstance(graph_node_input_1, np.ndarray) \ and 'merge_sub' in tf_layers_dict[graph_node_input_1.name] \ and tf_layers_dict[graph_node_input_1.name]['merge_sub'] @@ -5411,12 +5423,7 @@ def merge_two_consecutive_identical_ops_into_one( elif next_graph_node_o_op == 'Sub': # 8. `Add` -> `Sub` to `Single-Add` : `10 + 5 - 8 -> 10 - 3` if isinstance(next_graph_node_input_1, np.ndarray) or hasattr(next_graph_node_input_1, 'numpy'): - if isinstance(input_tensor_1, np.ndarray) or hasattr(input_tensor_1, 'numpy'): - input_tensor_1 = (input_tensor_1 - next_graph_node_input_1) - elif isinstance(input_tensor_2, np.ndarray) or hasattr(input_tensor_2, 'numpy'): - input_tensor_2 = (input_tensor_2 - next_graph_node_input_1) - tf_layers_dict[graph_node_output.name]['merge_add'] = True - tf_type = tf.identity + tf_type = tf.math.add elif isinstance(next_graph_node_input_2, np.ndarray) or hasattr(next_graph_node_input_2, 'numpy'): if isinstance(input_tensor_1, np.ndarray) or hasattr(input_tensor_1, 'numpy'): input_tensor_1 = (input_tensor_1 - next_graph_node_input_2)