From a296d5fe46f8382c43c60743006d2106cb2d6d8c Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Mon, 8 Jun 2026 19:48:21 -0700 Subject: [PATCH] fix(instantid): inline YuNet detection (the imagined _get_yunet doesn't exist) The InstantID restore module imported `_get_yunet` from `auto_config`, but auto_config doesn't export that function -- the YuNet singleton lives inline inside `detect_face()`. Caught by the Modal cert sweep: restore_faces post-pass failed (cannot import name '_get_yunet' from 'remove_ai_watermarks.auto_config'); keeping un-restored output Inline the YuNet builder the same way `photomaker_restore` does (read `auto_config._FACE_SCORE` and the bundled `face_detection_yunet_2023mar.onnx` asset, build a fresh `FaceDetectorYN` per call). This is the proven pattern from PhotoMaker and avoids a private-API drift between the modules. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/remove_ai_watermarks/instantid_restore.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/remove_ai_watermarks/instantid_restore.py b/src/remove_ai_watermarks/instantid_restore.py index d6c0992..5de3625 100644 --- a/src/remove_ai_watermarks/instantid_restore.py +++ b/src/remove_ai_watermarks/instantid_restore.py @@ -278,12 +278,14 @@ def restore_faces_instantid( import torch if detect_faces_fn is None: - from remove_ai_watermarks.auto_config import _get_yunet + from pathlib import Path - det = _get_yunet() + from remove_ai_watermarks import auto_config as _ac def _default_detect(bgr: NDArray[Any]) -> list[tuple[int, int, int, int]]: h_d, w_d = bgr.shape[:2] + model = Path(_ac.__file__).parent / "assets" / "face_detection_yunet_2023mar.onnx" + det = cv2.FaceDetectorYN.create(str(model), "", (w_d, h_d), _ac._FACE_SCORE, 0.3, 5000) det.setInputSize((w_d, h_d)) _, faces = det.detect(bgr) if faces is None: