Skip to content

Added WeChatQR-fix ONNX models#1329

Merged
asmorkalov merged 2 commits into
opencv:5.xfrom
omrope79:wechat-fix
May 30, 2026
Merged

Added WeChatQR-fix ONNX models#1329
asmorkalov merged 2 commits into
opencv:5.xfrom
omrope79:wechat-fix

Conversation

@omrope79

@omrope79 omrope79 commented Apr 1, 2026

Copy link
Copy Markdown

Merge with PR opencv/opencv#28746

@asmorkalov

Copy link
Copy Markdown
Contributor
  1. I propose to decouple the data on 2 prs: PR with new layers, PR with WeChat model files.
  2. For all new models we need source of the model and legal information. Small models are usually generated by Torch or ONNXScript or other trusted tool. See https://github.com/opencv/opencv_extra/blob/4.x/testdata/dnn/onnx/generate_onnx_models.py and https://github.com/opencv/opencv_extra/blob/4.x/testdata/dnn/onnx/generate_onnx_models_with_onnxscript.py. For the ONNX model converted from Caffe we need general instruction how to do it. I propose to submit a PR to main repo docs or Wiki page. For the last case you can share google doc with instruction or some other file.

@dkurt

dkurt commented Apr 2, 2026

Copy link
Copy Markdown
Member

Please also provide a short guide of how model converted from Caffe to ONNX

asmorkalov pushed a commit that referenced this pull request Apr 27, 2026
Adds ONNX test models and data for PriorBox and Nearest wechat-fix-layers models #1349

Merge with PR : opencv/opencv#28855

This PR is part 1 of the split from the original PR: Added WeChatQR-fix ONNX models #1329
It adds the required ONNX models and input/output data
@omrope79

Copy link
Copy Markdown
Author

I've removed the extra models from this branch and moved them to a dedicated PR here: #1349. Thanks!

@dkurt

dkurt commented Apr 29, 2026

Copy link
Copy Markdown
Member

@omrope79 does it mean this PR can be closed?

@abhishek-gola

Copy link
Copy Markdown
Contributor

@omrope79 does it mean this PR can be closed?

This PR contains ONNX models for Wechat converted from caffe, required for this PR: opencv/opencv#28746

@dkurt

dkurt commented Apr 30, 2026

Copy link
Copy Markdown
Member

Is that possible to add a guide how to export these models in ONNX? At least in https://github.com/omrope79/opencv-test-models/ README.md

@abhishek-gola

Copy link
Copy Markdown
Contributor

Is that possible to add a guide how to export these models in ONNX? At least in https://github.com/omrope79/opencv-test-models/ README.md

There is this PR (https://huggingface.co/opencv/opencv_contribution/discussions/3/files) on OpenCV hugging face, which has all the scripts.

@asmorkalov

Copy link
Copy Markdown
Contributor

@abhishek-gola Please add requirements.txt to the Higgingface repo. List if required packages is not clean. Also please add documentation page or wiki page about conversion steps. Users most probably have a lot of old models that they want to use with OpenCV 5.

@dkurt

dkurt commented Apr 30, 2026

Copy link
Copy Markdown
Member

Can we use huggingface URLs to download models?

@asmorkalov

Copy link
Copy Markdown
Contributor

Generally yes, but our CI has access issues with it (firewall). It'll be great to have alternative links to, if possible.

@asmorkalov

Copy link
Copy Markdown
Contributor
python3 -m onnxruntime.tools.check_onnx_model_mobile_usability ./detect.onnx 
INFO:  Checking detect.onnx for usability with ORT Mobile.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/tools/check_onnx_model_mobile_usability.py", line 47, in <module>
    check_usability()
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/tools/check_onnx_model_mobile_usability.py", line 34, in check_usability
    try_eps = usability_checker.analyze_model(args.model_path, skip_optimize=False, logger=logger)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/tools/mobile_helpers/usability_checker.py", line 694, in analyze_model
    optimize_model(model_path, tmp_path, use_external_initializers=True)
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/tools/onnx_model_utils.py", line 127, in optimize_model
    _ = ort.InferenceSession(str(model_path.resolve(strict=True)), so, providers=["CPUExecutionProvider"])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 504, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "/home/alexander/.local/lib/python3.12/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 599, in _create_inference_session
    sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from /mnt/Projects/Projects/tmp/wechat/detect.onnx failed:This is an invalid model. In Node, ("stage8_2/sum/prior_box", PriorBox, "", -1) : ("stage8_2/relu": tensor(float),"data/bn": tensor(float),) -> ("stage8_2/sum/prior_box": tensor(float),) , Error No Op registered for PriorBox with domain_version of 22

@omrope79

Copy link
Copy Markdown
Author

Hi @asmorkalov ,
To support detect.onnx on mobile, we should use OpenCV's DNN module, which now includes the required custom PriorBox layer (added in PR #28855). Running the model directly with standalone ONNX Runtime (ORT) will fail because ORT doesn't have a built-in implementation for the PriorBox operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants