Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

ValueError: axes don't match array when converting Yolov5s model #115

Closed
mikel-brostrom opened this issue Jul 20, 2022 · 1 comment
Closed
Labels
YOLOv5 Read the README.

Comments

@mikel-brostrom
Copy link

Issue Type

Bug

OS

Ubuntu

OS architecture

x86_64

Programming Language

Python

Framework

OpenVINO

Download URL for ONNX / OpenVINO IR

ONNX generated from Yolov5s with the export tool provided here: https://github.com/ultralytics/yolov5/blob/master/export.py

Convert Script

H=640
W=640

openvino2tensorflow \
    --model_path /datadrive/mikel/yolov5/openvino/best.xml \
    --output_saved_model \
    --output_pb \
    --output_no_quant_float32_tflite \
    --output_dynamic_range_quant_tflite \
    --output_weight_quant_tflite \
    --output_float16_quant_tflite \
    --output_integer_quant_tflite \
    --output_integer_quant_type 'uint8' \
    --string_formulas_for_normalization 'data / 255.0' \
    --output_tfjs \
    --output_coreml \
    --non_verbose \
    --weight_replacement_config replace.json

Description

ONNX is exported to OpenVINO by:

mo --input_model /path/to/my/yolov5s_best.onnx --output_dir ./openvino --data_type FP32

Then I use:

H=640
W=640
MODEL=v5lite_s
openvino2tensorflow \
--model_path /datadrive/mikel/yolov5/openvino/best.xml \
--output_saved_model \
--output_pb \
--output_no_quant_float32_tflite \
--output_dynamic_range_quant_tflite \
--output_weight_quant_tflite \
--output_float16_quant_tflite \
--output_integer_quant_tflite \
--output_integer_quant_type 'uint8' \
--string_formulas_for_normalization 'data / 255.0' \
--output_tfjs \
--output_coreml \
--non_verbose \
--weight_replacement_config replace.json

for TFLite conversion, where replace.json is:

{
    "format_version": 2,
    "layers": [
        {
            "layer_id": "509",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                0,
                3,
                1,
                2,
                4
            ]
        },
        {
            "layer_id": "512",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                4
            ]
        },
        {
            "layer_id": "513",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                2,
                2,
                81
            ]
        },
        {
            "layer_id": "570",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                0,
                3,
                1,
                2,
                4
            ]
        },
        {
            "layer_id": "573",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                4
            ]
        },
        {
            "layer_id": "574",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                2,
                2,
                81
            ]
        },
        {
            "layer_id": "631",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                0,
                3,
                1,
                2,
                4
            ]
        },
        {
            "layer_id": "634",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                4
            ]
        },
        {
            "layer_id": "635",
            "type": "Const",
            "replace_mode": "direct",
            "values": [
                2,
                2,
                81
            ]
        }
    ]
}

Relevant Log Output

ValueError: Dimensions must be equal, but are 80 and 3 for '{{node tf.math.add_54/Add}} = AddV2[T=DT_FLOAT](Placeholder, tf.math.add_54/Add/y)' with input shapes: [1,80,3,17,2], [1,3,80,80,2].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/datadrive/mikel/venvs/yolov5/bin/openvino2tensorflow", line 1056, in convert
    tf_layers_dict[layer_id] = tf.math.add(tf_layers_dict[edge_id0], tf_layers_dict[edge_id1].transpose(0,2,3,1))
ValueError: axes don't match array
ERROR: Please refer to 6-7 in the README first. https://github.com/PINTO0309/openvino2tensorflow

Source code for simple inference testing code

No response

@mikel-brostrom mikel-brostrom changed the title ValueError: axes don't match array when converting ValueError: axes don't match array when converting Yolov5s model Jul 20, 2022
@PINTO0309
Copy link
Owner

#102

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
YOLOv5 Read the README.
Projects
None yet
Development

No branches or pull requests

2 participants