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

Input and Output shape change after conversion to Tflite from OpenVINO #60

Closed letdivedeep closed 3 years ago

letdivedeep commented 3 years ago

Hi @PINTO0309

I have an onnx model which i need to convert to edge TPU. My onnx model takes the input as [1,3,288,352 ] as seen below

onnx_in

And the output of ONNX as [1x101x56x4]

onnx_out

When i convert the model to open vino i use this cmd

python /opt/intel/openvino_2021/deployment_tools/model_optimizer/mo.py \
  --input_model model.onnx \
  --input_shape [1,3,288,352] \
  --output_dir openvino \
  --data_type FP32

And then convert the openviono to edge tpu using this cmd

openvino2tensorflow \
  --model_path openvino/model.xml \
  --model_output_path saved_model \
  --output_saved_model \
  --output_h5 \
  --output_pb \
  --output_no_quant_float32_tflite \
--output_edgetpu \
  --output_weight_quant_tflite \
  --output_full_integer_quant_tflite \
 --output_integer_quant_type uint8 \
--output_onnx \
 --onnx_opset 11 \
--output_tftrt \
--output_integer_quant_tflite

I got this change in the tflite files, where the input and output shape is changed Input change

in

Output change

out

Can you point me to reason why its changing the shape ?

PINTO0309 commented 3 years ago

https://github.com/PINTO0309/openvino2tensorflow#6-7-replace-weights-or-constant-values-in-const-op If you want an accurate response, please provide a model. It is natural behavior for the structure to collapse in Reshape.

letdivedeep commented 3 years ago

@PINTO0309 Thanks for the reply

I have attached the model in this gdrive link

moreover, the results are very much hampered in the converted tflite from the openvino framework

PINTO0309 commented 3 years ago

Delete the layers of the OpenVINO XML file in order from the end and debug where the values are wrong. https://drive.google.com/drive/folders/10oXYlctN_1RXIZAzhSLzuBtiDdHwOS_d?usp=sharing

letdivedeep commented 3 years ago

@PINTO0309 for the reply

I will try your suggestions

PINTO0309 commented 3 years ago

Since there is no progress, I'm closing it.