Closed ukoehler closed 1 year ago
Hello @ukoehler , thanks for the feedback! Could you upload the model somewhere accessible for us?
Dear @fengyuentau,
thanks for the quick reply. I would quickly only know to upload it here. I have never tried to upload a file that big.
Cheers
Uwe
Sorry, wrong button.
Google drive is available.
OK, fist time using Google drive for something like this. The file should be available here: https://drive.google.com/file/d/1IXCkZbdQzcgZ3f2dAXQ5mZ67xo92Bvtz/view?usp=sharing
Hi, @ukoehler, your model is very complex.
Please try the following script to simplify your model first
import onnx
import onnxsim
import numpy as np
from onnx import load_model, save_model
path = "model.onnx"
path_saved = "model_sim.onnx"
onnx_model = onnx.load(path)
input_shape = np.array([1, 3, 224, 224])
input = dict()
input["x.1"] = input_shape
out = onnxsim.simplify(onnx_model, dynamic_input_shape=False, input_shapes=input)
onnx.save(out[0], path_saved)
And after that, everything should work fine.
There is a simplified model based on your google drive link. dm_nfnet_f0_sim.onnx
Dear @zihaomu,
many thanks for your help. I am only using, not creating the model. So far I did not know about the simplification possibility. I will try it and it might help with other models, as well.
Cheers
Uwe
Dear @zihaomu,
I tried you simplified model and it does load and produces reasonable output (I still have to find some undocumented parameters). That does give me a workaround (I am really grateful for that), but is still leaves an issue with OpenCV.
Cheers
Uwe
Hi @ukoehler, thanks for your report. The error was due to the reduce node cannot process the constant input. I'm considering whether to support this case.
Using opencv-python-rolling 4.6.0.20220924 this model can now be executed.
Dear @zihaomu, how to install dm_nfnet_f0_sim.onnx vscode Thanks
Detailed description
I converted the following DNN from PyTorch to ONNX and tried to load it using OpenCV: https://docs.openvino.ai/latest/omz_models_model_nfnet_f0.html#doxid-omz-models-model-nfnet-f0 The resulting ONNX file is 272 MB and can be provided, if needed.
I checked the ONNX using Pythin and onnx, as well as onnxruntime. Both claim that the model is OK. OpenCV, however, reports: `[ERROR:0@0.844] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1021) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [ReduceMean]:(onnx_node!ReduceMean_37) from domain='ai.onnx' Traceback (most recent call last): File "d:\Local\devel\Python\OpenCV\image_classification_nfnet_f0\inference.py", line 83, in
model = cv2.dnn.readNet(model_config)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode'
Steps to reproduce
model = cv2.dnn.readNet(model_file)
Issue submission checklist