PINTO0309 / onnx2tf

Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC). The purpose of this tool is to solve the massive Transpose extrapolation problem in onnx-tensorflow (onnx-tf). I don't need a Star, but give me a pull request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion of ScatterND operator results in error

AndreasBeering opened this issue · comments

Issue Type

Others

OS

Linux

onnx2tf version number

1.18.14

onnx version number

1.15.0

onnxruntime version number

1.16.3

onnxsim (onnx_simplifier) version number

0.4.35

tensorflow version number

2.15.0

Download URL for ONNX

https://github.com/AndreasBeering/ScaterND_TFLite/blob/main/dummy_model.zip

Parameter Replacement JSON

-

Description

  1. Research on RADAR networks. I got the original model from this [Repo] (https://github.com/CarkusL/CenterPoint/tree/main/onnx_model) and wanted to convert the Pointpillars model to TFLite. I created the linked dummy model to reproduce the error.
  2. Simple dummy script to reproduce the error:

import onnx2tf
import onnx

model = onnx.load("model/dummy_model.onnx")

onnx2tf.convert(
input_onnx_file_path="model/dummy_model.onnx",
output_folder_path='model',
output_keras_v3 = True,
output_signaturedefs = True,
non_verbose=False,
)

This results in the following output:

ValueError: Exception encountered when calling layer "tf.math.add" (type TFOpLambda).

Dimensions must be equal, but are 30000 and 3 for '{{node tf.math.add/Add}} = AddV2[T=DT_FLOAT](Placeholder, tf.math.add/Add/y)' with input shapes: [1,2,30000], [3].

Call arguments received by layer "tf.math.add" (type TFOpLambda):
• x=tf.Tensor(shape=(1, 2, 30000), dtype=float32)
• y=tf.Tensor(shape=(3,), dtype=float32)
• name=None

  1. I tried to upgrade the opset (its at 11) - different inputs, another conversion from a different Repo so far. What confuses me is that the tf.math.add is complaining about a y Tensor with shape (3,) - I would assume something related to (1x30000x64).

  2. ScatterND is a part of several Radar networks and would be great to be converted to TF for further usage there.

I am open for further questions!

Best

onnx2tf -i dummy_model.onnx -kat IN_a IN_b
ERROR: The trace log is below.
Traceback (most recent call last):
  File "/home/b920405/.local/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 309, in print_wrapper_func
    result = func(*args, **kwargs)
  File "/home/b920405/.local/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 382, in inverted_operation_enable_disable_wrapper_func
    result = func(*args, **kwargs)
  File "/home/b920405/.local/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 52, in get_replacement_parameter_wrapper_func
    func(*args, **kwargs)
  File "/home/b920405/.local/lib/python3.10/site-packages/onnx2tf/ops/ScatterND.py", line 186, in make_node
    tf.tensor_scatter_nd_update(
  File "/home/b920405/.local/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/b920405/.local/lib/python3.10/site-packages/keras/src/layers/core/tf_op_layer.py", line 119, in handle
    return TFOpLambda(op)(*args, **kwargs)
  File "/home/b920405/.local/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
TypeError: Exception encountered when calling layer "tf.tensor_scatter_nd_update" (type TFOpLambda).

Value passed to parameter 'indices' has DataType float32 not in list of allowed values: int16, int32, int64, uint16

Call arguments received by layer "tf.tensor_scatter_nd_update" (type TFOpLambda):
  • tensor=tf.Tensor(shape=(1, 262144, 64), dtype=float32)
  • indices=tf.Tensor(shape=(1, 30000, 2), dtype=float32)
  • updates=tf.Tensor(shape=(1, 30000, 64), dtype=float32)
  • name='ScatterND_1'

ERROR: input_onnx_file_path: dummy_model.onnx
ERROR: onnx_op_name: ScatterND_1
ERROR: Read this and deal with it. https://github.com/PINTO0309/onnx2tf#parameter-replacement
ERROR: Alternatively, if the input OP has a dynamic dimension, use the -b or -ois option to rewrite it to a static shape and try again.
ERROR: If the input OP of ONNX before conversion is NHWC or an irregular channel arrangement other than NCHW, use the -kt or -kat option.
ERROR: Also, for models that include NonMaxSuppression in the post-processing, try the -onwdt option.

You have been advised by TensorFlow.

Value passed to parameter 'indices' has 
DataType float32 not in list of allowed values: int16, int32, int64, uint16

image

To begin with, the ONNX ScatterND you shared with us does not follow ONNX specifications.

https://github.com/onnx/onnx/blob/main/docs/Changelog.md#scatternd-18

image

If there is no activity within the next two days, this issue will be closed automatically.