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

untraced function _jit_compiled_convolution_op #33

Closed tino926 closed 1 year ago

tino926 commented 1 year ago

i am now trying to convert yolov5-6.1's model to tflite int8 model. I use yolov5-6.1's official method (set opset=11) to export pytorch model to onnx model

then i use your method to convert the model from onnx to tflite as:

python converter.py \
  --weights .../best.onnx \
  --outpath "./test01" --formats "tflite" --int8 --imgroot "../val2017/" \
  --int8mean 0 0 0 --int8std 255 255 255

during the process, i got this WARNING message:

WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 56). These functions will not be directly callable after loading.
INFO:tensorflow:Assets written to: /tmp/tmp408fv3h7/assets
INFO:tensorflow:Assets written to: /tmp/tmp408fv3h7/assets
/home/tino/venv/onnx2tflite/lib/python3.8/site-packages/tensorflow/lite/python/convert.py:766: UserWarning: Statistics for quantized inputs were expected, but not specified; continuing anyway.
  warnings.warn("Statistics for quantized inputs were expected, but not "

the version of installed packages is: python: 3.8 onnx: 1.13.0 onnxruntime: 1.14.0 numpy: 1.24.2 tensorflow: 2.9.0 opencv-python: 4.7.0 onnx-simplifier: 0.4.17

MPolaris commented 1 year ago

Hello, Is the model generated normally? I think you can ignore this WARNING message if tflite model can running normally.

MPolaris commented 1 year ago

I have tried, and the output int8 model can work normally.

tino926 commented 1 year ago

Hi,

After conducting some investigations, I am confident that your tool works great.

I wanted to share some additional information for your reference.

I actually modified yolov5-6.1's exporting code by removing some final layers, which resulted in a .onnx model with three output nodes. However, after using your tool to convert the .onnx model, I noticed that the order of the output nodes in the resulting .tflite model was changed. As a result, my c++ code displayed incorrect detection results due to the mismatched order of the anchors and output nodes. Perhaps there is a way to improve this?

Additionally, would you consider adding the command edgetpu_compiler -s -a [tflite file] -o [output folder] to your project to output the edgetpu model altogether?

MPolaris commented 1 year ago

Hi. I'm glad my tools can help you. For yolov5, tool can work with two format models, one is 3 outputs and one is 1 output(with coordinate processing). About order changed of outputs , I have tried some methods to make it matched, but failed... For edgetpu_compiler, it's not in planning, because I'm not known with it, but welcome for PR.