TrungTran commited on
Commit
5a621f1
Β·
verified Β·
1 Parent(s): c8599c1

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +13 -9
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 margin padding, sorted by area desc.
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
- # Add margin, clamp to image bounds
151
- x0 = max(0, x - margin)
152
- y0 = max(0, y - margin)
153
- x1 = min(w, x + fw + margin)
154
- y1 = min(h, y + fh + margin)
 
 
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.760** (beats MiVOLO v2 measured 3.859) |
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) |