# Yunet Model gaves an unexpected output sometimes

**URL:** <https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315>\
**Category:** C++\
**Tags:** dnn\
**Created:** [August 21, 2023, 7:23pm UTC](https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315 "2023-08-21T19:23:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mentejoao](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mentejoao](https://forum.opencv.org/u/mentejoao)\
**Post date:** [August 21, 2023, 7:23pm UTC](https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315/1 "2023-08-21T19:23:43Z")

</div>

In the context of creating an application to extract Face Rectangles coords of a great number of faces, in a file path, in the same size dimensions, I got an issue with Yunet.  
Code example:

```auto
for( ... ) // iterates in all images of the filepat
...
FaceDetector->setInputSize(image.size());
cv::Mat faces(1, 15, CV_32FC1, cv::Scalar(0));
FaceDetector->detect(image, faces);
...

```

In [docs of Yunet usage](https://docs.opencv.org/4.x/df/d20/classcv_1_1FaceDetectorYN.html), it says the expected output for this model is a [num\_faces, 15]. But in some random cases, I have only one face and the model gaves me [2 x 15] with infinitely large numbers at the first 15 positions and the expected 15 numbers after these.

Unexpected output for example: [-inf, -inf, inf, inf, -7.3996823e+29, 8.3138902e+29, -6.9410597e+29, 9.5680955e+29, -3.6332516e+29, 6.361716e+29, -5.7762872e+29, 8.271784e+29, -4.8886777e+29, 9.2385431e+29, 1;  
8.0682755, 1.9483109, 89.627586, 123.62176, 34.569054, 43.413845, 74.630112, 48.56892, 48.431858, 69.483932, 30.405964, 89.4823, 65.017296, 93.899574, 0.99998468]

In someway, it looks kinda the model find a true face in the infinity (a position completely out of my image).  
Note: all my images have the same dimension, an image contains exactly one person and the face it’s totally in the expected range of Yunet input’s " [**faces of pixels between around 10x10 to 300x30**"](https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet). This bug occurs for different images in different executions. Example: in my first execution, the bug appeared for the image10, the next execution my image10 gaves me the correct [1x15] and then the bug appeared in image94. Maybe it could be a garbage initialization issue, but I always initialize my cv::Mat faces with zero, so I don’t know if the reason could still be related to this way… Any idea?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 22, 2023, 5:36am UTC](https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315/2 "2023-08-22T05:36:34Z")

</div>

which exact opencv version and yunet model ?

unlikely the cause of your problem, but please don’t pre-allocate this:

> [@mentejoao](#):
>
> ```auto
> cv::Mat faces(1, 15, CV_32FC1, cv::Scalar(0));
> 
> ```

it’s going to be [overwritten anyway](https://github.com/opencv/opencv/blob/ca0bd70cde431b1dd211254011dd9bcf965f582f/modules/objdetect/src/face_detect.cpp#L119) and you’re fooling yourself believing something about type, shape or content like this

---

<div class="post-metadata">

**Author:** ![mentejoao](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mentejoao](https://forum.opencv.org/u/mentejoao)\
**Post date:** [August 23, 2023, 1:38pm UTC](https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315/3 "2023-08-23T13:38:26Z")

</div>

My model version was deprecated. Thanks for answering. It seems the new model version fixed it.

---

<div class="post-metadata">

**Author:** ![davlid](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@davlid](https://forum.opencv.org/u/davlid)\
**Post date:** [January 25, 2024, 11:37am UTC](https://forum.opencv.org/t/yunet-model-gaves-an-unexpected-output-sometimes/14315/4 "2024-01-25T11:37:08Z")

</div>

I’m seeing the same thing with the face\_detection\_yunet\_2023mar.onnx model from the model zoo… Any pointer on what it could be? Is there a newer model than this one available?
