From 9fc5bfc2c435fb71ab7ece6d06ec4c86e28f487e Mon Sep 17 00:00:00 2001 From: fiatcode Date: Fri, 27 Feb 2026 21:50:37 +0700 Subject: [PATCH] fix: raise detection confidence threshold to 0.7, move model cache to project dir --- .gitignore | 13 +++++++++++++ src/faceblur/cli.py | 15 ++++++++++++++- src/faceblur/detect.py | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62a329e --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv + +# Downloaded ML models +models/ diff --git a/src/faceblur/cli.py b/src/faceblur/cli.py index 0362f0f..685c5e2 100644 --- a/src/faceblur/cli.py +++ b/src/faceblur/cli.py @@ -1,9 +1,16 @@ """CLI module for faceblur-poc.""" import argparse +import os import sys from pathlib import Path +# Set model cache to project-local models/ directory before importing uniface +os.environ.setdefault( + "UNIFACE_CACHE_DIR", + str(Path(__file__).resolve().parent.parent.parent / "models"), +) + from .video import extract_frames from .detect import FaceDetector from .cluster import cluster_faces @@ -35,6 +42,12 @@ def main(): detect_parser.add_argument( "--min-samples", type=int, default=2, help="DBSCAN min_samples" ) + detect_parser.add_argument( + "--confidence", + type=float, + default=0.7, + help="Minimum face detection confidence (0-1)", + ) args = parser.parse_args() @@ -66,7 +79,7 @@ def run_detect(args): sys.exit(1) print("\n[2/5] Initializing face detector...") - detector = FaceDetector() + detector = FaceDetector(confidence_threshold=args.confidence) print("\n[3/5] Detecting faces...") all_faces = [] diff --git a/src/faceblur/detect.py b/src/faceblur/detect.py index 7eeccab..81182dc 100644 --- a/src/faceblur/detect.py +++ b/src/faceblur/detect.py @@ -26,8 +26,8 @@ class FaceData: class FaceDetector: """Face detector using RetinaFace + ArcFace via UniFace.""" - def __init__(self): - self.detector = RetinaFace() + def __init__(self, confidence_threshold: float = 0.7): + self.detector = RetinaFace(confidence_threshold=confidence_threshold) self.recognizer = ArcFace() def detect_faces(self, frame_path: Path, frame_index: int) -> List[FaceData]: