Closed wwdok closed 1 year ago
First, optimize the model with onnx-simplifier. (This work is expected to become unnecessary in the future.)
onnxsim model.onnx model.onnx
Next, create a JSON file to customize the shape transformation behavior of Reshape_77
.
https://github.com/PINTO0309/onnx2tf#parameter-replacement
{
"format_version": 1,
"operations": [
{
"op_name": "Reshape_77",
"param_target": "inputs",
"param_name": "onnx::Reshape_600",
"values": [1,1,1,128]
}
]
}
Finally, use onnx2tf to transform the model.
onnx2tf -i model.onnx -prf replace.json
:
:
:
saved_model output started ==========================================================
saved_model output complete!
WARNING:absl:Please consider providing the trackable_obj argument in the from_concrete_functions. Providing without the trackable_obj argument is deprecated and it will use the deprecated conversion path.
Estimated count of arithmetic ops: 32.942 M ops, equivalently 16.471 M MACs
Float32 tflite output complete!
Estimated count of arithmetic ops: 32.942 M ops, equivalently 16.471 M MACs
Float16 tflite output complete!
Hi @PINTO0309 , the 0.0.28 seems not fully fix this issue, i upgrade to 0.0.28 an rerun onnx2tf -i model.onnx
without -prf replace.json
, it throw another error:
...
INFO: onnx_op_type: Mul onnx_op_name: Mul_78
INFO: input_name.1: onnx::Reshape_396 shape: [1, 128, 6, 6] dtype: float32
INFO: input_name.2: onnx::Mul_419 shape: [1, 128, 1, 1] dtype: float32
INFO: output_name.1: onnx::MaxPool_420 shape: [1, 128, 6, 6] dtype: float32
ERROR: The trace log is below.
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\onnx2tf\utils\common_functions.py", line 176, in print_wrapper_func
line 225, in inverted_operation_enable_disable_wrapper_func
result = func(*args, **kwargs)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\onnx2tf\utils\common_functions.py", line 32, in get_replacement_parameter_wrapper_func
func(*args, **kwargs)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\onnx2tf\ops\Mul.py", line 84, in make_node
tf.math.multiply(
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\keras\layers\core\tf_op_layer.py", line 107, in handle
return TFOpLambda(op)(*args, **kwargs)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
ValueError: Exception encountered when calling layer "tf.math.multiply_4" (type TFOpLambda).
Dimensions must be equal, but are 6 and 128 for '{{node tf.math.multiply_4/Mul}} = Mul[T=DT_FLOAT](Placeholder, Placeholder_1)' with input shapes: [1,6,6,128], [1,128,1,1].
Call arguments received by layer "tf.math.multiply_4" (type TFOpLambda):
• x=tf.Tensor(shape=(1, 6, 6, 128), dtype=float32)
• y=tf.Tensor(shape=(1, 128, 1, 1), dtype=float32)
• name='Mul_78'
If you say in this case whose Reshape OP with dimensional decompression, it must specify -prf replace.json
, that's also fine ~
If you say in this case whose Reshape OP with dimensional decompression, it must specify -prf replace.json, that's also fine ~
You are right.
In order to accommodate models such as YOLOv5 and YOLOv7, which contain a large number of multi-dimensional Reshapes and Transposes beyond 5 dimensions, it is necessary to adjust the behavior of the tool by specifying the -prf
parameter at this time.
It has been two years without coming up with a good plan of action on this issue. I welcome pull requests if you have any good ideas.
Issue Type
Others
Download URL for ONNX
model.zip
Description
I am trying to convert above model.onnx to tflite format by executing
log:
onnx2tf -i EyeNet.onnx
, but it throw error at the concat op: