MPolaris / onnx2tflite

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

KeyError: 'NonMaxSuppression not implemented yet' (YOLOv7 tiny onnx to tflite) #43

Closed kizmoya closed 1 year ago

kizmoya commented 1 year ago

Hello, I tried to convert YOLOv7 ONNX model to tflite. When I tried in Intel Macbook, I got some error message.

$ python converter.py --weights "../yolov7-tiny.onnx" --outpath "./" --formats "tflite" 2023-05-08 19:48:50.472025: 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: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Checking 0/1... INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Reshape will process tensor after change back to NCHW format. INFO:deformation_layers ::Transpose will process tensor after change back to NCHW format. Traceback (most recent call last): File "~/onnx2tflite/converter.py", line 108, in run() File "~/onnx2tflite/converter.py", line 92, in run onnx_converter( File "~/onnx2tflite/converter.py", line 21, in onnx_converter keras_model = keras_builder(model_proto, native_groupconv) File "~/onnx2tflite/utils/builder.py", line 75, in keras_builder raise KeyError(f"{op_name} not implemented yet") KeyError: 'NonMaxSuppression not implemented yet'

Is there something I can do to fix this? Looking forward to your reply.

MPolaris commented 1 year ago

Hello, it's seems the post-process operation is exported with model, you may check how to remove it.


# without `--end2end`
python export.py --weights yolov7-tiny.pt --simplify --img-size 640 640 --max-wh 640
MPolaris commented 1 year ago

NonMaxSuppression op is a typical dynamic operator, tflite is not friendly to it as my known. So we always make model graph is static, not dynamic.