Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -124,11 +124,13 @@ def _load_detector():
|
|
| 124 |
_DETECTOR = "unavailable"
|
| 125 |
|
| 126 |
|
|
|
|
|
|
|
|
|
|
| 127 |
def _detect_faces(img_rgb: np.ndarray,
|
| 128 |
-
min_face_px: int = 20,
|
| 129 |
-
margin: int = 15) -> list[tuple[int, int, int, int]]:
|
| 130 |
"""
|
| 131 |
-
Returns list of (x0, y0, x1, y1) with
|
| 132 |
Falls back to empty list if YuNet is unavailable.
|
| 133 |
"""
|
| 134 |
if _DETECTOR == "unavailable" or _DETECTOR is None:
|
|
@@ -147,11 +149,13 @@ def _detect_faces(img_rgb: np.ndarray,
|
|
| 147 |
bboxes = []
|
| 148 |
for face in faces:
|
| 149 |
x, y, fw, fh = face[:4].astype(int)
|
| 150 |
-
#
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
if (x1 - x0) >= min_face_px and (y1 - y0) >= min_face_px:
|
| 156 |
bboxes.append((x0, y0, x1, y1))
|
| 157 |
|
|
@@ -271,7 +275,7 @@ Upload a photo. **YuNet** auto-detects faces, then **FaceAge-DINOv3** predicts a
|
|
| 271 |
|
| 272 |
| | |
|
| 273 |
|--|--|
|
| 274 |
-
| π LAGENDA 84k MAE | **3.
|
| 275 |
| π§ Backbone | DINOv3-ViT-L/16 (Meta AI, 307M params) |
|
| 276 |
| β‘ Speed | ~100 ms / face on CPU (ONNX FP32) |
|
| 277 |
| π Detector | YuNet (OpenCV, ~350 KB) |
|
|
|
|
| 124 |
_DETECTOR = "unavailable"
|
| 125 |
|
| 126 |
|
| 127 |
+
_FACE_PAD = 0.10 # 10% proportional padding β matches LAGENDA benchmark MAE=3.555
|
| 128 |
+
|
| 129 |
+
|
| 130 |
def _detect_faces(img_rgb: np.ndarray,
|
| 131 |
+
min_face_px: int = 20) -> list[tuple[int, int, int, int]]:
|
|
|
|
| 132 |
"""
|
| 133 |
+
Returns list of (x0, y0, x1, y1) with 10% proportional padding, sorted by area desc.
|
| 134 |
Falls back to empty list if YuNet is unavailable.
|
| 135 |
"""
|
| 136 |
if _DETECTOR == "unavailable" or _DETECTOR is None:
|
|
|
|
| 149 |
bboxes = []
|
| 150 |
for face in faces:
|
| 151 |
x, y, fw, fh = face[:4].astype(int)
|
| 152 |
+
# 10% proportional padding (matches training/benchmark setup)
|
| 153 |
+
pw = int(fw * _FACE_PAD)
|
| 154 |
+
ph = int(fh * _FACE_PAD)
|
| 155 |
+
x0 = max(0, x - pw)
|
| 156 |
+
y0 = max(0, y - ph)
|
| 157 |
+
x1 = min(w, x + fw + pw)
|
| 158 |
+
y1 = min(h, y + fh + ph)
|
| 159 |
if (x1 - x0) >= min_face_px and (y1 - y0) >= min_face_px:
|
| 160 |
bboxes.append((x0, y0, x1, y1))
|
| 161 |
|
|
|
|
| 275 |
|
| 276 |
| | |
|
| 277 |
|--|--|
|
| 278 |
+
| π LAGENDA 84k MAE | **3.555** (beats MiVOLO v2 paper 3.650, face-only) |
|
| 279 |
| π§ Backbone | DINOv3-ViT-L/16 (Meta AI, 307M params) |
|
| 280 |
| β‘ Speed | ~100 ms / face on CPU (ONNX FP32) |
|
| 281 |
| π Detector | YuNet (OpenCV, ~350 KB) |
|