Why I am not getting the same FPS for YuNet model

Hello everyone,

I’m running a face detection application using OpenCV’s official YuNet model (face_detection_yunet_2023mar.onnx).

  • First Approach: I use cv2.FaceDetectorYN.create() and call .detect().
  • Second Approach: I use cv2.dnn.readNet(theonnxmodel), as shown in the code below.

When measuring FPS:

  • The first approach achieves 35 FPS.
  • The second approach, using cv2.dnn.readNet(), achieves only 3.5 FPS.

Question:

Could someone provide a detailed explanation of why there is such a large FPS difference between the two methods?

Thanks in advance!

    def detect(self, input_image):
        if input_image is None or input_image.size == 0:
            return None
        
        if input_image.shape[:2] != (self.inputH, self.inputW):
            raise ValueError("Size does not match. Call set_input_size(size) if input size does not match the preset size")

        pad_image = pad_with_divisor(input_image, self.padH, self.padW, self.inputH, self.inputW)
        input_blob = cv2.dnn.blobFromImage(pad_image)
        
        self.net.setInput(input_blob)
        output_names = ["cls_8", "cls_16", "cls_32", "obj_8", "obj_16", "obj_32", "bbox_8", "bbox_16", "bbox_32", "kps_8", "kps_16", "kps_32"]
        output_blobs = self.net.forward(output_names)

        return post_process(output_blobs, self.strides, self.padW, self.padH, self.scoreThreshold, self.nmsThreshold, self.topK)