Repository navigation
objdetect: Fix INT8 casting in FaceDetectorYN - #28806
Closed
Muhammad-Kamran-Khan wants to merge 1 commit into
Closed
Muhammad-Kamran-Khan wants to merge 1 commit into
Muhammad-Kamran-Khan wants to merge 1 commit into
Conversation
4 tasks done
Contributor
|
Fixed CV_8S to float pointer bug using convertTo. Added INT8 regression test.
Muhammad-Kamran-Khan
force-pushed
the
fix-yunet-int8-parsing
branch
from
April 14, 2026 08:32
04975e9 to
a4a318c
Compare
Author
|
Hi @asmorkalov, I have reverted the irrelevant imgcodecs files so the PR is clean now. I have also added the regression test for the INT8 model in modules/objdetect/test/test_face.cpp as requested. The test safely skips locally, I don't know why. Please review the updated PR. Thank you! |
Contributor
|
You need to create PR with the same branch name in opencv_extra repo and add model file there. |
Author
|
Hi @asmorkalov, I have created the PR in the opencv_extra repo with the exact same branch name and added the model file. Here is the link: |
Contributor
|
Tested branch locally. It does not fix model behaviour. Facedetect sample still does not detect faces with int8 model. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug where
FaceDetectorYNfails to detect any faces when using INT8 quantized models (specificallyface_detection_yunet_2023mar_int8.onnx).Root Cause:
In
modules/objdetect/src/face_detect.cpp, thepostProcessfunction extracts output blobs and immediately casts their data tofloat*. For INT8 models, these blobs are of typeCV_8S. Casting a 1-byte integer array directly to a 4-byte float pointer results in memory misinterpretation (garbage values), causing all bounding box scores to drop near zero and fail thescoreThresholdcheck.Solution:
Added a step to safely cast the extracted tensors to
CV_32Fusingcv::Mat::convertTobefore applying thefloat*read. This acts as a safe cast for quantized models and is practically a no-op for models that already outputCV_32F.Related Issue
Fixes #28798
Checklist