Skip to content

dnn onnx: invalid shape dimension and wrong results in test case Test_ONNX_layers.OpenAI_CLIP_head #24300

@fengyuentau

Description

@fengyuentau

System Information

latest opencv and lastest onnxruntime

Detailed description

Related PR: #23419 and opencv/opencv_extra#1049.

In the above PR, several fixes are indtroduced for the clip head. Those fixes are fine, but the manually generated onnx model named "clip-vit-base-head.onnx" is invalid and cannot be run by onnxruntime:

  1. In the Expand operator, shape input should be of type int64 instead of int32. Please use onnx.checker.check_model(model) (it checks operator definitions and so on) before saving a manually generated onnx model.
  2. Having that fixed, onnxruntime still complains invalid shape in the Expand operator. Changing the shape value from [1, 1, -1] to [1, 1, 1] fixes the problem. Please run the manually generated onnx model with onnxruntime to check whether it is all valid.

cc @dkurt

Steps to reproduce

Install onnxruntime, then

import numpy as np
from onnxruntime import InferenceSession


net = InferenceSession("./clip-vit-base-head.onnx")
out = net.run([], {"input": np.random.randn(1, 1, 3).astype(np.float32)})
print(out[0].shape)

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions