Skip to content

Commit

Permalink
TFLite does not support TrueDiv(INT), so TrueDiv is avoided if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
PINTO0309 committed Oct 27, 2022
1 parent 34491fa commit eb3c1f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Self-Created Tools to convert ONNX files (NCHW) to TensorFlow format (NHWC). The
8. Calculation error due to scaling up or down by specifying a `scale` when resizing images

The above differences often cannot be dealt with by simply converting the model in a straightforward manner. Therefore, you need to replace the model yourself in advance with an operation that is less prone to errors.
- [x] TFLite does not support `TrueDiv`(INT), so `TrueDiv` is avoided if possible.
- [x] Implement the `Resize` process for the 5D tensor.
- [x] Add process to replace `Asin` with `pseudo-Asin`.
- [x] Add process to replace `Acos` with `pseudo-Acos`.
Expand Down Expand Up @@ -70,7 +71,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.0.25
ghcr.io/pinto0309/onnx2tf:1.0.26
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.0.25'
__version__ = '1.0.26'
11 changes: 8 additions & 3 deletions onnx2tf/ops/Div.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ def make_node(
const_or_var_2=input_tensor_2,
)

# TFLite does not support TrueDiv(INT), so TrueDiv is avoided if possible
x_is_integer = input_tensor_1.dtype in target_cast_dtype
y_is_integer = input_tensor_2.dtype in target_cast_dtype
xy_is_integer = x_is_integer and y_is_integer

divided_tensor = tf.math.divide(
x=input_tensor_1,
y=input_tensor_2,
x=input_tensor_1 if not xy_is_integer else tf.cast(input_tensor_1, dtype=tf.float32),
y=input_tensor_2 if not xy_is_integer else tf.cast(input_tensor_2, dtype=tf.float32),
name=graph_node.name,
)

if dtype in target_cast_dtype:
if xy_is_integer and dtype in target_cast_dtype:
divided_tensor = tf.cast(divided_tensor, dtype=dtype)

tf_layers_dict[graph_node_output.name]['tf_node'] = divided_tensor
Expand Down

0 comments on commit eb3c1f1

Please sign in to comment.