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

Output result doesn't match between IR and TFLite #64

Closed YenchungChen closed 3 years ago

YenchungChen commented 3 years ago

1. OS you are using: Ubuntu 18.04

2. OS Architecture: x86_64

3. Version of OpenVINO: 2021.4

4. Version of TensorFlow: v2.3.0

5. Version of openvino2tensorflow: v1.17.3

5. Download URL for OpenVINO IR (.bin/.xml) model https://download.01.org/opencv/2021/openvinotoolkit/2021.2/open_model_zoo/models_bin/3/gaze-estimation-adas-0002/FP32/

6. Issue Details

I'm converting an identical model mentioned in this closed issue. The issue above is solved and the converted model from PINTO_model_zoo works fine.

Although the correct converted model is provided by author in the above link, I tried to convert it through openvion2tensorflow. Following are the visualization of the IR model (.xml) and the corresponding TFLite model (converted by openvino2tensorflow): IR model

gaze_xml

TFLite model

gaze_tflite_b4correct

The output shape of StridedSlice in TFLite model is (1, 1, 1).

PINTO0309 commented 3 years ago

Thank you for posting a very clear issue.

The slice position is misaligned because it is difficult to mechanically identify the axis of a 3D slice. This is a specification of the tool.

There are two ways to solve this problem.

  1. How to process .xml by hand to remove unwanted layers and optimize the model.
  2. How to correct the Const value of the axis of StridedSlice according to the following explanation. https://github.com/PINTO0309/openvino2tensorflow#6-7-replace-weights-or-constant-values-in-const-op-and-add-transpose-or-reshape-just-before-the-operation-specified-by-layer_id

Depending on the complexity of the model structure, you can choose the simpler of the above two. Since this issue is likely to be simple, requiring only the deletion of a few layers at the end of the model, I will show the steps for 1.

The red frame in the figure below is almost a pointless process, so I manually processed the XML file and removed it. Please compare gaze-estimation-adas-0002.xml and gaze-estimation-adas-0002_org.xml to see how to edit them. You can easily optimize the structure by simply modifying the connection information between layers.

Screenshot 2021-08-16 11:48:08  : Screenshot 2021-08-16 11:49:42 Screenshot 2021-08-16 11:51:12

YenchungChen commented 3 years ago

I've exercised both ways and they work like magic. Really appreciate for the fast reply and clear explanation. Hope everyone enjoys this tool as much as I do.