Closed dino-illumix closed 1 year ago
hi, mmdeploy does not support onnx2tf. It seems something wrong when parsing Pad
node. Maybe you could try upgrade opset_version.
This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.
What's the correct way to create TFLite models from open_mmlab models if not by using onnx2tf? There does not appear to be any way to directly create either TFLite models or Tensorflow models that can be converted to TFLite.
I tried ugrading opset version. The highest version which would run onnx2tf was v17 but this still gives the same keyerror. I'd really like to build this MobilenetV3 model but it really needs to be in tflite format (that's the whole point of building a Mobilenet model as I need it to be small and run on device).
This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.
This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.
Checklist
Describe the bug
Conversion of Mobilenet_v3 models created with mmsegmentation converted using mmdeploy pytorch to ONNX converter appear to have been coverted correctly but then fail during conversion to tensorflow:
import onnx from onnx_tf.backend import prepare import tensorflow as tf
Load the ONNX model
onnx_model = onnx.load(onnx_model_path)
Export TF model:
tf_rep = prepare(onnx_model) tf_rep.export_graph(tf_model_path)
produces the following error: For Mobilenet_v2 models it works fine.
(mmdeploy) D:\Projects\mmsegmentation>python illumix_utils/convert_onnx_to_tflite.py C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow_addons\utils\tfa_eol_msg.py:23: UserWarning:
TensorFlow Addons (TFA) has ended development and introduction of new features. TFA has entered a minimal maintenance and release mode until a planned end of life in May 2024. Please modify downstream libraries to take dependencies from other repositories in our TensorFlow community (e.g. Keras, Keras-CV, and Keras-NLP).
For more information see: https://github.com/tensorflow/addons/issues/2807
warnings.warn( 2023-09-08 17:08:01.657263: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Traceback (most recent call last): File "D:\Projects\mmsegmentation\illumix_utils\convert_onnx_to_tflite.py", line 43, in
tf_rep.export_graph(tf_model_path)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\onnx_tf\backend_rep.py", line 143, in export_graph
signatures=self.tf_module.call.get_concrete_function(
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\polymorphic_function.py", line 1189, in get_concrete_function
concrete = self._get_concrete_function_garbage_collected(*args, kwargs)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\polymorphic_function.py", line 1169, in _get_concrete_function_garbage_collected
self._initialize(args, kwargs, add_initializers_to=initializers)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\polymorphic_function.py", line 694, in _initialize
self._variable_creation_fn # pylint: disable=protected-access
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\tracing_compiler.py", line 176, in _get_concrete_function_internal_garbage_collected
concretefunction, = self._maybe_define_concrete_function(args, kwargs)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\tracing_compiler.py", line 171, in _maybe_define_concrete_function
return self._maybe_define_function(args, kwargs)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\tracing_compiler.py", line 398, in _maybe_define_function
concrete_function = self._create_concrete_function(
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\tracing_compiler.py", line 305, in _create_concrete_function
func_graph_module.func_graph_from_py_func(
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\framework\func_graph.py", line 1055, in func_graph_from_py_func
func_outputs = python_func(*func_args, *func_kwargs)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\polymorphic_function.py", line 597, in wrapped_fn
out = weak_wrapped_fn().wrapped(args, kwds)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\tracing_compiler.py", line 453, in bound_method_wrapper
return wrapped_fn(*args, kwargs)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\autograph_util.py", line 52, in autograph_handler
raise e.ag_error_metadata.to_exception(e)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\eager\polymorphic_function\autograph_util.py", line 41, in autograph_handler
return api.converted_call(
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 439, in converted_call
result = converted_f(*effective_args, *kwargs)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_file9n_szo61.py", line 30, in tf__call
ag.for_stmt(ag__.ld(self).graph_def.node, None, loop_body, get_state, set_state, (), {'iterate_names': 'node'})
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 454, in for_stmt
forfn(iter, extra_test, body, get_state, set_state, symbol_names, opts)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 505, in _py_for_stmt
body(target)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 471, in protected_body
original_body(protected_iter)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_file9n_szo61.py", line 23, in loop_body
output_ops = ag.converted_call(ag.ld(self).backend._onnx_node_to_tensorflow_op, (ag__.ld(onnx_node), ag.ld(tensor_dict), ag.ld(self).handlers), dict(opset=ag.ld(self).opset, strict=ag__.ld(self).strict), fscope)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 439, in converted_call
result = converted_f(effective_args, kwargs)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filekyr48t.py", line 62, in tf_onnx_node_to_tensorflow_op
ag__.if_stmt(ag.ld(handlers), if_body_1, else_body_1, get_state_1, set_state_1, ('doreturn', 'retval'), 2)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1269, in if_stmt
_py_if_stmt(cond, body, orelse)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1322, in _py_if_stmt
return body() if cond else orelse()
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filekyr48t.py", line 56, in if_body_1
ag.if_stmt(ag__.ld(handler), if_body, else_body, get_state, set_state, ('doreturn', 'retval'), 2)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1269, in if_stmt
_py_if_stmt(cond, body, orelse)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1322, in _py_if_stmt
return body() if cond else orelse()
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filekyr48t.py", line 48, in ifbody
retval = ag__.converted_call(ag.ld(handler).handle, (ag.ld(node),), dict(tensor_dict=ag__.ld(tensor_dict), strict=ag.ld(strict)), fscope)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 439, in converted_call
result = converted_f(effective_args, kwargs)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filei8y3rukj.py", line 41, in tfhandle
ag.if_stmt(ag.ld(ver_handle), if_body, else_body, get_state, set_state, ('doreturn', 'retval'), 2)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1269, in if_stmt
_py_if_stmt(cond, body, orelse)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1322, in _py_if_stmt
return body() if cond else orelse()
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filei8y3rukj.py", line 33, in ifbody
retval = ag__.converted_call(ag.ld(ver_handle), (ag__.ld(node),), dict(ag__.ld(kwargs)), fscope)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 439, in converted_call
result = converted_f(effective_args, kwargs)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_filedt4vrp2y.py", line 12, in tfversion
retval_ = ag__.converted_call(ag.ld(cls)._common, (ag__.ld(node),), dict(ag.ld(kwargs)), fscope)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\impl\api.py", line 439, in converted_call
result = converted_f(*effective_args, **kwargs)
File "C:\Users\mdino\AppData\Local\Temp__autograph_generatedfile0e349o2q.py", line 122, in tfcommon
ag.if_stmt(ag__.ld(cls).SINCE_VERSION < 11, if_body_1, else_body_1, get_state_1, set_state_1, ('constant_values', 'paddings'), 2)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1269, in if_stmt
_py_if_stmt(cond, body, orelse)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\control_flow.py", line 1322, in _py_if_stmt
return body() if cond else orelse()
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_file0e349o2q.py", line 119, in else_body_1
constant_values = ag.if_exp(ag.converted_call(ag.ld(len), (ag.ld(node).inputs,), None, fscope) == 3, lambda : ag__.ld(tensor_dict)[ag.ld(node).inputs[2]], lambda : 0, 'ag.converted_call(len, (node.inputs,), None, fscope) == 3')
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\conditional_expressions.py", line 27, in if_exp
return _py_if_exp(cond, if_true, if_false)
File "C:\Users\mdino\anaconda3\envs\mmdeploy\lib\site-packages\tensorflow\python\autograph\operators\conditional_expressions.py", line 52, in _py_if_exp
return if_true() if cond else if_false()
File "C:\Users\mdino\AppData\Local\Temp__autograph_generated_file0e349o2q.py", line 119, in
constant_values = ag .if_exp(ag.converted_call(ag.ld(len), (ag.ld(node).inputs,), None, fscope) == 3, lambda : ag__.ld(tensor_dict)[ag.ld(node).inputs[2]], lambda : 0, 'ag__.converted_call(len, (node.inputs,), None, fscope) == 3')
tensorflow.python.autograph.pyct.error_utils.MultilineMessageKeyError: in user code:
Reproduction
Use
./tools/deploy.py configs/mmseg/segmentation_onnxruntime_static-512x512.py
to create an ONNX model from a Mobilenet_v3 model created using mmsegmentation
then run the following python commands:
import onnx from onnx_tf.backend import prepare import tensorflow as tf
Load the ONNX model
onnx_model = onnx.load(onnx_model_path)
Export TF model:
tf_rep = prepare(onnx_model) tf_rep.export_graph(tf_model_path)
Environment
Error traceback
No response