MPolaris / onnx2tflite

Tool for onnx->keras or onnx->tflite. Hope this tool can help you.
Apache License 2.0
526 stars 42 forks source link

onnx converting to tflite got an error, is there any solutions? #51

Closed Licolnlee closed 1 year ago

Licolnlee commented 1 year ago

Checking 0/1... shape[0] of input "input" is dynamic, we assume it presents batch size and set it as 1 when testing. If it is not wanted, please set the it manually by --test-input-shape (see onnxsim -h for the details). Traceback (most recent call last): File "G:\onnx2tflite-main\converter.py", line 108, in run() File "G:\onnx2tflite-main\converter.py", line 92, in run onnx_converter( File "G:\onnx2tflite-main\converter.py", line 21, in onnx_converter keras_model = keras_builder(model_proto, native_groupconv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "G:\onnx2tflite-main\utils\builder.py", line 82, in keras_builder tf_tensor[node_outputs[index]] = tf_operator(tf_tensor, onnx_weights, node_inputs, op_attr, index=index)(_inputs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "G:\onnx2tflite-main\layers\common_layers.py", line 58, in call return tf.pad(inputs, self.pad, mode=self.model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lee\AppData\Roaming\Python\Python311\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "C:\Users\Lee\AppData\Roaming\Python\Python311\site-packages\keras\src\layers\core\tf_op_layer.py", line 119, in handle return TFOpLambda(op)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lee\AppData\Roaming\Python\Python311\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None ^^^^^^^^^^^^^^^ ValueError: Exception encountered when calling layer "tf.pad" (type TFOpLambda).

Value of argument mode expected to be one of "CONSTANT", "REFLECT", or "SYMMETRIC". Received mode = EDGE

Call arguments received by layer "tf.pad" (type TFOpLambda): • tensor=tf.Tensor(shape=(1, 64, 64, 3), dtype=float32) • paddings=[['0', '0'], ['1', '1'], ['1', '1'], ['0', '0']] • mode='EDGE' • constant_values=0 • name=None

MPolaris commented 1 year ago

Maybe you can manually set mode to "CONSTANT", "REFLECT", or "SYMMETRIC" or upgrade your tensorflow version.

Licolnlee commented 1 year ago

Maybe you can manually set mode to "CONSTANT", "REFLECT", or "SYMMETRIC" or upgrade your tensorflow version.

Yes, But I can't find any mode setting options that can manually set mode to "CONSTANT", "REFLECT", or "SYMMETRIC", Cause I was transforming my pytorch model to tflite.

MPolaris commented 1 year ago

Maybe you can manually set mode to "CONSTANT", "REFLECT", or "SYMMETRIC" or upgrade your tensorflow version.

Yes, But I can't find any mode setting options that can manually set mode to "CONSTANT", "REFLECT", or "SYMMETRIC", Cause I was transforming my pytorch model to tflite.

I mean that you can force mode=['CONSTANT'.'REFLECT','SYMMETRIC'] at code(common_layers.py TFPad class). Choose which mode is closest to 'EDGE'.