Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load model ONNX 4.5.5 or 4.6.0 #22247

Closed
2 of 4 tasks
ctcx opened this issue Jul 14, 2022 · 1 comment
Closed
2 of 4 tasks

Unable to load model ONNX 4.5.5 or 4.6.0 #22247

ctcx opened this issue Jul 14, 2022 · 1 comment
Labels
category: dnn (onnx) ONNX suport issues in DNN module category: dnn feature

Comments

@ctcx
Copy link

ctcx commented Jul 14, 2022

System information (version)
  • OpenCV => 4.5.5/4.6.0
  • Operating System / Platform => MacOS 12.4 (21F79) Apple M1 Pro
  • Compiler => Visual Studio Code/ python /c++
Detailed description
python:

4.6.0
[ERROR:0@0.079] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp (1021) handleNode DNN/ONNX: ERROR during processing node with 3 inputs and 1 outputs: [Clip]:(onnx_node!StatefulPartitionedCall/center_net_mobile_net_v2fpn_feature_extractor/model_1/model/Conv1_relu/Relu6) from domain='ai.onnx'
Traceback (most recent call last):
  File "/Users/tony/Documents/Works/project/nts/cpp/python/pose.py", line 5, in <module>
    net = cv2.dnn.readNetFromONNX("./model_pb.onnx")  # 加载训练好的识别模型
cv2.error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode'
> Node [Clip@ai.onnx]:(onnx_node!StatefulPartitionedCall/center_net_mobile_net_v2fpn_feature_extractor/model_1/model/Conv1_relu/Relu6) parse error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1934: error: (-2:Unspecified error) in function 'void cv::dnn::dnn4_v20220524::ONNXImporter::parseClip(cv::dnn::dnn4_v20220524::LayerParams &, const opencv_onnx::NodeProto &)'
> >  (expected: 'node_proto.input_size() == 1'), where
> >     'node_proto.input_size()' is 3
> > must be equal to
> >     '1' is 1
> 
c++:
版本:4.5.5
[ERROR:0@2.046] global /tmp/opencv-20220225-83415-181ywau/opencv-4.5.5/modules/dnn/src/onnx/onnx_importer.cpp (909) handleNode DNN/ONNX: ERROR during processing node with 3 inputs and 1 outputs: [Clip]:(StatefulPartitionedCall/center_net_mobile_net_v2fpn_feature_extractor/model_1/model/Conv1_relu/Relu6:0) from domain='ai.onnx'
OpenCV(4.5.5) /tmp/opencv-20220225-83415-181ywau/opencv-4.5.5/modules/dnn/src/onnx/onnx_importer.cpp:928: error: (-2:Unspecified error) in function 'handleNode'
> Node [Clip@ai.onnx]:(StatefulPartitionedCall/center_net_mobile_net_v2fpn_feature_extractor/model_1/model/Conv1_relu/Relu6:0) parse error: OpenCV(4.5.5) /tmp/opencv-20220225-83415-181ywau/opencv-4.5.5/modules/dnn/src/onnx/onnx_importer.cpp:1613: error: (-2:Unspecified error) in function 'void cv::dnn::dnn4_v20211220::ONNXImporter::parseClip(cv::dnn::dnn4_v20211220::LayerParams &, const opencv_onnx::NodeProto &)'
> >  (expected: 'node_proto.input_size() == 1'), where
> >     'node_proto.input_size()' is 3
> > must be equal to
> >     '1' is 1
> 
Steps to reproduce
  1. download model: https://tfhub.dev/google/movenet/singlepose/thunder/4?tf-hub-format=compressed
  2. convert model : python -m tf2onnx.convert --saved-model ./movenet_singlepose_thunder_4 --output model_pb.onnx
  3. load model the follow code:
# python
import cv2

print(cv2.__version__)
net = cv2.dnn.readNetFromONNX("./model_pb.onnx") 
image = cv2.imread("person.jpeg") 
blob = cv2.dnn.blobFromImage(image) 
net.setInput(blob)  
out = net.forward() 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdexcept>

using namespace cv;
using namespace cv::dnn;
using namespace std;

int main() try {
    system("color F0");

    cout << "version:" << cv::getVersionString() << endl;

    string model = "../model/model_pb.onnx";
    Net net = dnn::readNet(model);
    if(net.empty()){
        cout << "确认是否输入了空的模型文件" << endl;
        return -1;
    }
    vector<string> layerNames = net.getLayerNames();
    for (size_t i = 0; i < layerNames.size(); i++)
    {
        int ID = net.getLayerId(layerNames[i]);
        Ptr<Layer> layer = net.getLayer(ID);
        cout << "网络层数" << ID << " 网络层名称 " << layerNames[i] << " 类型 " << layer->type.c_str() << endl;
    }
    
    cout << "ok" << endl;
}catch(std::exception const &ex){
    cerr<<ex.what()<<endl;
}
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
@ctcx
Copy link
Author

ctcx commented Jul 15, 2022

#21698

@ctcx ctcx closed this as completed Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: dnn (onnx) ONNX suport issues in DNN module category: dnn feature
Projects
None yet
Development

No branches or pull requests

2 participants