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

Yolov5 with Shuffle_Block model conversion error, ValueError: Dimension size must be evenly divisible by 3 but is 16 #77

Closed AlexisPapaioannou closed 2 years ago

AlexisPapaioannou commented 2 years ago

1. OS you are using e.g. Ubuntu 20.04, WIndows10, etc

Windows 10

2. OS Architecture e.g. x86_64, armv7l, aarch64, etc

3. Version of OpenVINO e.g. 2021.2.185, etc

openvino2tensorflow v1.24.8

4. Version of TensorFlow e.g. v2.4.1, tf-nightly==2.5.0.dev20210128, etc

TensorFlow 2.6.0

8. Version of ONNX e.g. v1.8.0, etc

ONNX 1.8.0

9. Download URL for ONNX model

10. Download URL for OpenVINO IR (.bin/.xml) model

11. URL of the repository from which the transformed model was taken

https://github.com/ppogg/YOLOv5-Lite/blob/master/models/v5Lite-s.yaml

layer_type: Sigmoid layer_id: 311 input_layer0: layer_id=310: Tensor("Transpose_7:0", shape=(1, 3, 16, 16, 6), dtype=float32) tf_layers_dict: Tensor("Sigmoid_33:0", shape=(1, 3, 16, 16, 6), dtype=float32)

layer_type: Const layer_id: 312 tf_layers_dict: (1,)

layer_type: Const layer_id: 313 tf_layers_dict: (3,)

ERROR: Dimension size must be evenly divisible by 3 but is 16 Number of ways to split should evenly divide the split dimension for '{{node lambda_6/Split}} = Split[T=DT_FLOAT, num_split=3](lambda_6/Split/split_dim, Sigmoid_33)' with input shapes: [], [1,3,16,16,6] and with computed input tensors: input[0] = <3>. ERROR: model_path : /content/drive/MyDrive/yolov5_greyscale_new_version/runs/train/exp/weights/optimizations/best_opt.xml ERROR: weights_path: /content/drive/MyDrive/yolov5_greyscale_new_version/runs/train/exp/weights/optimizations/best_opt.bin ERROR: layer_id : 314 ERROR: The trace log is below. Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py", line 1812, in _create_c_op c_op = pywrap_tf_session.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension size must be evenly divisible by 3 but is 16 Number of ways to split should evenly divide the split dimension for '{{node lambda_6/Split}} = Split[T=DT_FLOAT, num_split=3](lambda_6/Split/split_dim, Sigmoid_33)' with input shapes: [], [1,3,16,16,6] and with computed input tensors: input[0] = <3>.

13. Issue Details

I tried to convert a yolov5 model with shuffleNet, but I received the above error. Is there any solution? Also, I tried to implemented the solution from https://github.com/PINTO0309/openvino2tensorflow/issues/38 but the problem didn't solve it.

PINTO0309 commented 2 years ago

Please provide the .onnx and .xml and .bin. Otherwise, I will not respond at all.

AlexisPapaioannou commented 2 years ago

*Here you can find the xml file: https://drive.google.com/file/d/1fbarCM7jWa1Gioqj-d-iNqsDjHv1Tl3C/view?usp=sharing

*the .bin file: https://drive.google.com/file/d/1zj3OiInSmHrIPf--5deverxQn4MUd_vd/view?usp=sharing

*the .onnx file: https://drive.google.com/file/d/1yzxj0GjErLk7poqGivex6_69Yp07O11D/view?usp=sharing

Thanks a lot!

AlexisPapaioannou commented 2 years ago

And here is the new error

error

PINTO0309 commented 2 years ago

Has this model been trained by MS-COCO? Or is it your own data set?

AlexisPapaioannou commented 2 years ago

With my custom dataset

PINTO0309 commented 2 years ago

I don't normally respond to individual requirements as it is not helpful to other engineers, but I will reply just in case. Next time I will not respond to individual requirements. Also, please try to at least read the README and do what you can before posting your question.

The tflite generated by the following procedure has not been tested at all. This is because it is trained on a proprietary data set. I don't know the label.

Due to the large number of 5D transposes, if the inferred results are not correct, you can adjust the JSON yourself.

1,3,16,16,6 N,C,D,H,W

1,16,16,6,3 N,D,H,W,C

openvino2tensorflow \ --model_path best_opt.xml \ --output_saved_model \ --output_pb \ --output_no_quant_float32_tflite \ --weight_replacement_config replace.json


![model_float32 tflite](https://user-images.githubusercontent.com/33194443/141873767-53dbe99c-2e56-4d5a-aa5f-51d96fb9e90f.png)
AlexisPapaioannou commented 2 years ago

Thank you very much, I appreciate it! And one more question, is it possible by adding 3 Reshape layers before the 3 last Concatenation layers to change the 5d to 4d removing the first dimension? As the tflite which I use supports only Concatenation with max 4d.

PINTO0309 commented 2 years ago

I would insert Reshape before Split.

AlexisPapaioannou commented 2 years ago

Okay, thanks!