Failed to parse ONNX model

Hello, I’m trying to make a face recognition with OpenCV and ONNX models on a Raspberry Pi 5 but while I’m running my program it can parse ONNX shown as below (I’m using face_detection_yunet_2023mar.onnx and face_recognition_sface_2021dec.onnx from the OpenCV Zoo repo), can someone help me please?

image

can you replace the screenshot of the error message with the literal text of the error message? just copy the text out of the terminal, instead of screenshotting it.

your error says you tried this with OpenCV version 4.10. that is outdated. bug reports for outdated versions cannot be accepted because the issue might already have been fixed.

can you try reproducing the issue with the current release of OpenCV?

I’ve tried the 1.13 version and it still don’t work with the same error message:

terminate called after throwing an instance of ‘cv::Exception’
what():  OpenCV(4.13.0) /home/sasha/opencv/modules/dnn/src/onnx/onnx_importer.cpp:284: error: (-210:Unsupported format or combination of formats) Failed to parse ONNX model: /home/sasha/SPider/face_detection_yunet_2023mar.onnx in function ‘ONNXImporter’

Aborted

maybe is my code wrong? I don’t think it is but I’m gonna show it to be shure.

int facial_recognition() {
	cv::namedWindow("Frame", 0);
	cv::String detectionModelPath = "/home/sasha/SPider/face_detection_yunet_2023mar.onnx";
	cv::String recognizerModelPath = "/home/sasha/SPider/face_recognition_sface_2021dec.onnx";

	cv::Mat refImg = cv::imread("/home/sasha/SPider/.png");
	cv::Mat frame, faceRef, alignedRedFace, featureRef, facesGlobal;

	cv::Ptr<cv::FaceDetectorYN> detectorRef = cv::FaceDetectorYN::create(detectionModelPath, "", cv::Size(320, 320));
	detectorRef->setInputSize(refImg.size());
	detectorRef->detect(refImg, faceRef);

	cv::Ptr<cv::FaceRecognizerSF> recognizerRef = cv::FaceRecognizerSF::create(recognizerModelPath, "");
	recognizerRef->alignCrop(refImg, faceRef(0), alignedRedFace);
	recognizerRef->feature(alignedRedFace, featureRef);

	cv::Ptr<cv::FaceDetectorYN> detectorGlobal = cv::FaceDetectorYN::create(detectionModelPath, "", cv::Size(320, 320));
	cv::Ptr<cv::FaceRecognizerSF> recognizerGlobal = cv::FaceRecognizerSF::create(recognizerModelPath, "");

	detectorGlobal->setInputSize(cv::Size(1280, 720));


	cv::VideoCapture cap(0);

	while (1) {

		cap >> frame;
		detectorGlobal->detect(frame, facesGlobal);

		for (int i = 0; i < facesGlobal.rows; i++) {
			cv::Rect box(facesGlobal.at<float>(i, 0), facesGlobal.at<float>(i, 1), facesGlobal.at<float>(i, 2), facesGlobal.at<float>(i, 3));
			cv::rectangle(frame, box, cv::Scalar(0, 255, 255, 255), 3);
		}

		cv::imshow("Frame", frame);
		if (cv::waitKey(1) == 'q') {
			break;
		}
	
	}

	cap.release();

	return 0;
}

This is where the error is thrown:

sadly, that’s not telling much about what exactly the ONNX importer code has an issue with.

I’ve got to ask: how did you download the model files? did you click this or git clone the repo?

if you obtained your ONNX files any other way, there’s a chance you downloaded something that wasn’t meant to be downloaded (such as a web page), and that isn’t the actual data.

In any case, you should submit this situation as an issue on OpenCV’s github. you said the ONNX file comes from the OpenCV model zoo? then link to it in your issue. if it’s in the model zoo, then the ONNX importer code should not have had such an issue.

The core developers or someone else might tell you, in the issue, if there are ways to get more debug logging/output out of the library.