Skip to content

Got error when export TFlite with NMS  #6799

@chinaandylee

Description

@chinaandylee

Search before asking

Question

When I export tflite model with opt --nms
python export.py --weights yolov5s.pt --include tflite --nms
I got the following error:
.....
tf.expand_dims (TFOpLambda) (1, 25200, 1, 4) 0 tf.concat[0][0]


tf.math.multiply (TFOpLambda) (1, 25200, 2) 0 tf.operators.getitem_1[0][0]
tf.operators.getitem_2[0][0]


tf.image.combined_non_max_suppr CombinedNonMaxSuppre 0 tf.expand_dims[0][0]
tf.math.multiply[0][0]

Total params: 7,015,519
Trainable params: 0
Non-trainable params: 7,015,519


2022-02-27 14:40:41.858021: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider a
voiding using them.
Found untraced functions such as tf_conv_2_layer_call_fn, tf_conv_2_layer_call_and_return_conditional_losses, tf_conv_3_layer_call_fn, tf_conv_3_layer_call_and
_return_conditional_losses, tf_conv_4_layer_call_fn while saving (showing 5 of 520). These functions will not be directly callable after loading.
Found untraced functions such as tf_conv_2_layer_call_fn, tf_conv_2_layer_call_and_return_conditional_losses, tf_conv_3_layer_call_fn, tf_conv_3_layer_call_and
_return_conditional_losses, tf_conv_4_layer_call_fn while saving (showing 5 of 520). These functions will not be directly callable after loading.
Assets written to: last_saved_model\assets
TensorFlow SavedModel: export success, saved as last_saved_model (238.6 MB)

TensorFlow Lite: starting export with tensorflow 2.4.0...
Found untraced functions such as tf_conv_2_layer_call_fn, tf_conv_2_layer_call_and_return_conditional_losses, tf_conv_3_layer_call_fn, tf_conv_3_layer_call_and
_return_conditional_losses, tf_conv_4_layer_call_fn while saving (showing 5 of 520). These functions will not be directly callable after loading.
Found untraced functions such as tf_conv_2_layer_call_fn, tf_conv_2_layer_call_and_return_conditional_losses, tf_conv_3_layer_call_fn, tf_conv_3_layer_call_and
_return_conditional_losses, tf_conv_4_layer_call_fn while saving (showing 5 of 520). These functions will not be directly callable after loading.
Assets written to: C:\Users\kk\AppData\Local\Temp\tmp7pgu55vr\assets
2022-02-27 14:41:35.278574: I tensorflow/core/grappler/devices.cc:69] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2022-02-27 14:41:35.281165: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2022-02-27 14:41:35.283499: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2022-02-27 14:41:35.297874: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:928] Optimization results for grappler item: graph_to_optimize
function_optimizer: function_optimizer did nothing. time = 0.001ms.
function_optimizer: function_optimizer did nothing. time = 0ms.

2022-02-27 14:41:36.286075: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:316] Ignored output_format.
2022-02-27 14:41:36.288583: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:319] Ignored drop_control_dependency.
2022-02-27 14:41:36.360661: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
loc(callsite("model/tf.image.combined_non_max_suppression/combined_non_max_suppression/CombinedNonMaxSuppression"("C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\s
ite-packages\tensorflow\python\eager\def_function.py":1205:0) at callsite("C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\tensorflow\python\eager\def
_function.py":1299:0 at callsite("C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\tensorflow\lite\python\lite.py":847:0 at callsite("export.py":324:0
at callsite("export.py":488:0 at callsite("C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\autograd\grad_mode.py":28:0 at callsite("export.py":5
39:0 at "export.py":544:0)))))))): error: 'tf.CombinedNonMaxSuppression' op is neither a custom op nor a flex op
error: failed while converting: 'main': Ops that can be supported by the flex runtime (enabled via setting the -emit-select-tf-ops flag):
tf.CombinedNonMaxSuppression {clip_boxes = false, device = "", pad_per_class = false}

TensorFlow Lite: export failure: C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\tensorflow\python\eager\def_function.py:1205:0: error: 'tf.CombinedNo
nMaxSuppression' op is neither a custom op nor a flex op
C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\tensorflow\python\eager\def_function.py:1299:0: note: called from
C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\tensorflow\lite\python\lite.py:847:0: note: called from
export.py:324:0: note: called from
export.py:488:0: note: called from
C:\Users\kk\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\autograd\grad_mode.py:28:0: note: called from
export.py:539:0: note: called from
export.py:544:0: note: called from
### :0: error: failed while converting: 'main': Ops that can be supported by the flex runtime (enabled via setting the -emit-select-tf-ops flag):
tf.CombinedNonMaxSuppression {clip_boxes = false, device = "", pad_per_class = false}

Export complete (65.58s)
Results saved to E:\python_resource\code_resource\pytorch\yolov5-master
Detect: python detect.py --weights last_saved_model
PyTorch Hub: model = torch.hub.load('ultralytics/yolov5', 'custom', 'last_saved_model')
Validate: python val.py --weights last_saved_model
Visualize: https://netron.app

Any help will be appreciated!

Additional

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TODOHigh priority itemsquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions