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) <noreply@anthropic.com>
This commit is contained in:
Victor Kuznetsov
2026-06-08 19:48:21 -07:00
parent 70e8b3a517
commit a296d5fe46
@@ -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: