Closed ingura closed 1 year ago
I recommend the use of the latest tool here. No conversion errors occur and no accuracy errors are introduced. It also supports complex models such as Transformer. openvino2tensorflow is not actively maintained at this time. https://github.com/PINTO0309/onnx2tf
Converting a Yolov5 model to tensorflow #135
pip install -U onnx \
&& pip install -U nvidia-pyindex \
&& pip install -U onnx-graphsurgeon \
&& pip install -U onnxruntime \
&& pip install -U onnxsim \
&& pip install -U simple_onnx_processing_tools \
&& pip install -U onnx2tf \
&& pip install -U h5py==3.7.0
onnx2tf -i yolov7-tiny.onnx -osd -oh5 -cotof
Awesome! thank you.
Issue Type
Bug
OS
Windows
OS architecture
x86_64
Programming Language
Python
Framework
TensorFlowLite
Download URL for ONNX / OpenVINO IR
pip install onnx==1.12.0 pip install onnxruntime onnxsim onnx-tf pip install openvino-dev==2022.3.0 pip install tensorflow-intel==2.10.0 pip install tensorflow-datasets pip install openvino2tensorflow --upgrade
Convert Script
Download the model
wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-tiny.pt
Convert the Pytorch model to ONNX model
python export.py --weights yolov7-tiny.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640
Convert ONNX model to OpenVINO IR
mo --input_model yolov7-tiny.onnx --input_shape [1,3,640,640] --output_dir model_openvino/ --data_type FP32
Convert model input shape to NHWC
python openvino2tensorflow.py --model_path model_openvino/yolov7-tiny.xml --model_output_path models-NHWC-final/ --output_saved_model --output_h5 --output_pb --output_no_quant_float32_tflite
Description
I am trying to use to convert the Pythorch version of the Yolov7-tiny model (https://github.com/WongKinYiu/yolov7) to the tflite version of the same model. If I take the conversion path PyTorch -> ONNX -> TF/TFlite the ONNX model works fine however the order of the input channels of the resulting TF model is NcHW instead of the NHWc required by TfLite. To correct the issue I am trying to use openvino2tensorflow using the conversion path PyTorch -> ONNX -> OpenVINO ->openvino2tensorflow -> TensorFlow / Tensorflow Lite. The conversion works without exceptions until i reach the openvino2tensorflow step where i use the following script:
python openvino2tensorflow.py --model_path model_openvino/yolov7-tiny.xml --model_output_path models-NHWC-final/ --output_saved_model --output_h5 --output_pb --output_no_quant_float32_tflite
Relevant Log Output
Source code for simple inference testing code