From 2b7c40494eba83916e847c0a4755b1d4303408fd Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 21 Nov 2024 17:08:09 -0700 Subject: [PATCH] Adjust to score system --- frigate/embeddings/maintainer.py | 11 ++++++----- frigate/util/model.py | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index bebed8fb8..2e66b5e19 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -456,15 +456,15 @@ class EmbeddingMaintainer(threading.Thread): if not res: return - sub_label, distance = res + sub_label, score = res logger.debug( - f"Detected best face for person as: {sub_label} with distance {distance}" + f"Detected best face for person as: {sub_label} with score {score}" ) - if id in self.detected_faces and distance >= self.detected_faces[id]: + if id in self.detected_faces and score <= self.detected_faces[id]: logger.debug( - f"Recognized face distance {distance} is greater than previous face distance ({self.detected_faces.get(id)})." + f"Recognized face distance {score} is less than previous face distance ({self.detected_faces.get(id)})." ) return @@ -473,11 +473,12 @@ class EmbeddingMaintainer(threading.Thread): json={ "camera": obj_data.get("camera"), "subLabel": sub_label, + "subLabelScore": score }, ) if resp.status_code == 200: - self.detected_faces[id] = distance + self.detected_faces[id] = score def _detect_license_plate(self, input: np.ndarray) -> tuple[int, int, int, int]: """Return the dimensions of the input image as [x, y, width, height].""" diff --git a/frigate/util/model.py b/frigate/util/model.py index 748b1358d..3532cf65a 100644 --- a/frigate/util/model.py +++ b/frigate/util/model.py @@ -165,7 +165,7 @@ class FaceClassificationModel: def __init__(self, config: FaceRecognitionConfig, db: SqliteQueueDatabase): self.config = config self.db = db - self.recognizer = cv2.face.LBPHFaceRecognizer_create(radius=4, threshold=config.threshold) + self.recognizer = cv2.face.LBPHFaceRecognizer_create(radius=4, threshold=(1 - config.threshold) * 1000) self.label_map: dict[int, str] = {} def __build_classifier(self) -> None: @@ -198,5 +198,6 @@ class FaceClassificationModel: if index == -1: return None - return self.label_map[index], distance + score = 1.0 - (distance / 1000) + return self.label_map[index], round(score, 2)