Skip to content

Commit

Permalink
Merge pull request #1041 from serengil/feat-task-2502-common-confiden…
Browse files Browse the repository at this point in the history
…ce-score-for-detectors

common confidence scales
  • Loading branch information
serengil authored Feb 25, 2024
2 parents 3ebcc82 + 7ee55cb commit ca8a149
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion deepface/detectors/Dlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
left_eye = (shape.part(2).x, shape.part(2).y)
right_eye = (shape.part(0).x, shape.part(0).y)

# never saw confidence higher than +3.5 github.com/davisking/dlib/issues/761
confidence = scores[idx]

facial_area = FacialAreaRegion(
Expand All @@ -99,7 +100,7 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
h=h,
left_eye=left_eye,
right_eye=right_eye,
confidence=confidence,
confidence=min(max(0, confidence), 1.0),
)
resp.append(facial_area)

Expand Down
2 changes: 1 addition & 1 deletion deepface/detectors/OpenCv.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def detect_faces(self, img: np.ndarray) -> List[FacialAreaRegion]:
h=h,
left_eye=left_eye,
right_eye=right_eye,
confidence=confidence,
confidence=(100 - confidence) / 100,
)
resp.append(facial_area)

Expand Down
5 changes: 5 additions & 0 deletions tests/visual-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"yolov8",
]


# verification
for model_name in model_names:
obj = DeepFace.verify(
Expand All @@ -46,6 +47,7 @@
embedding = embedding_obj["embedding"]
logger.info(f"{model_name} produced {len(embedding)}D vector")


# find
dfs = DeepFace.find(
img_path="dataset/img1.jpg", db_path="dataset", model_name="Facenet", detector_backend="mtcnn"
Expand All @@ -54,6 +56,7 @@
logger.info(df)



# img_paths = ["dataset/img11.jpg", "dataset/img11_reflection.jpg", "dataset/couple.jpg"]
img_paths = ["dataset/img11.jpg"]
for img_path in img_paths:
Expand Down Expand Up @@ -84,6 +87,8 @@
assert isinstance(face_obj["facial_area"]["right_eye"][1], int)

assert isinstance(face_obj["confidence"], float)
assert face_obj["confidence"] <= 1

plt.imshow(face)
plt.axis("off")
plt.show()
Expand Down

0 comments on commit ca8a149

Please sign in to comment.