PINTO0309 / openvino2tensorflow

This script converts the ONNX/OpenVINO IR model to Tensorflow's saved_model, tflite, h5, tfjs, tftrt(TensorRT), CoreML, EdgeTPU, ONNX and pb. PyTorch (NCHW) -> ONNX (NCHW) -> OpenVINO (NCHW) -> openvino2tensorflow -> Tensorflow/Keras (NHWC/NCHW) -> TFLite (NHWC/NCHW). And the conversion from .pb to saved_model and from saved_model to .pb and from .pb to .tflite and saved_model to .tflite and saved_model to onnx. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support.
MIT License
334 stars 40 forks source link

Yolo V5 conversion problem: How can I properly make weight replacement file #54

Closed LightCannon closed 3 years ago

LightCannon commented 3 years ago

Hello. First, I want to thank you for this awesome repository.

I am trying to convert yolov5 model from onnx (coming from .pt format) to .tflite (with int8 quantized). The problem can be narrowed down to the fact that our model has a 5D Reshape layer, which -as per mentioned in readme.md- is reported to have problems currently. Your solution is "writing weights replacement file". Unfortunately, this parts lacks detailed documentation. Going straight to my question, I want to know how can write a replacement file for the layer(s) causing problems. it is clear that the replacement json needs values, and I am not sure how can I get those values to put inside my own replacement file. I have pt model, onnx model and OpenVino model. How can get the replacement fields from (any) of those? Thanks in advance, Regards.

LightCannon commented 3 years ago

Also, is there any plan to fix this without any workarounds?

PINTO0309 commented 3 years ago

I have added a large amount of explanation of the procedure without any leaks. https://github.com/PINTO0309/openvino2tensorflow#6-7-2-example

Also, is there any plan to fix this without any workarounds?

It's not that I'm too busy to implement it. It is impossible to convert mechanically. This is why neither Google, Microsoft, nor Facebook provide an official tool that can cleanly convert NCHW to NHWC. If you think it's too much trouble, just don't use this tool. There are some tools that are very useful, but produce not-so-beautiful models, so I'll introduce them here just in case. https://github.com/onnx/onnx-tensorflow