From 2b1fc069ebca41736dee5aada4f7183e0af0f0ff Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 26 Mar 2025 07:59:31 -0600 Subject: [PATCH] Don't assume landmark file is downloaded --- frigate/data_processing/common/face/model.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frigate/data_processing/common/face/model.py b/frigate/data_processing/common/face/model.py index 5e15a2441..20db5173e 100644 --- a/frigate/data_processing/common/face/model.py +++ b/frigate/data_processing/common/face/model.py @@ -18,10 +18,7 @@ class FaceRecognizer(ABC): def __init__(self, config: FrigateConfig) -> None: self.config = config - self.landmark_detector = cv2.face.createFacemarkLBF() - self.landmark_detector.loadModel( - os.path.join(MODEL_CACHE_DIR, "facedet/landmarkdet.yaml") - ) + self.init_landmark_detector() @abstractmethod def build(self) -> None: @@ -37,6 +34,13 @@ class FaceRecognizer(ABC): def classify(self, face_image: np.ndarray) -> tuple[str, float] | None: pass + def init_landmark_detector(self) -> None: + landmark_model = os.path.join(MODEL_CACHE_DIR, "facedet/landmarkdet.yaml") + + if os.path.exists(landmark_model): + self.landmark_detector = cv2.face.createFacemarkLBF() + self.landmark_detector.loadModel(landmark_model) + def align_face( self, image: np.ndarray, @@ -130,6 +134,7 @@ class LBPHRecognizer(FaceRecognizer): def build(self): if not self.landmark_detector: + self.init_landmark_detector() return None labels = [] @@ -207,6 +212,7 @@ class ArcFaceRecognizer(FaceRecognizer): def build(self): if not self.landmark_detector: + self.init_landmark_detector() return None face_embeddings_map: dict[str, list[np.ndarray]] = {}