File size: 2,282 Bytes
cb68e53
 
 
 
 
 
 
 
 
 
 
 
 
7c552e4
 
cb68e53
 
7c552e4
 
 
 
 
 
 
 
 
 
cb68e53
a283bc3
03a9dd6
 
cb68e53
 
 
 
7c552e4
 
 
cb68e53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c552e4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: Face Detection (SCRFD comparison)
emoji: πŸ™‚
colorFrom: indigo
colorTo: purple
sdk: gradio
sdk_version: 6.20.0
app_file: app.py
pinned: false
---

# Face Detection β€” SCRFD model comparison

Upload one image; it is run through **all three** SCRFD face detectors at once and
the annotated results are shown **side by side** so you can compare them in a single
pass β€” no model picker.

| Model | File | Input | Notes |
|-------|------|-------|-------|
| SCRFD-500MF | `models/det_500m.onnx` | 640Γ—640 | lighter / faster |
| SCRFD-2.5GF | `models/det_2.5g.onnx` | 640Γ—640 | heavier / usually higher recall |
| SCRFD @ 480 | `models/det_480.onnx` | 480Γ—480 | same SCRFD-500MF weights as `det_500m`, exported at a smaller input β€” fastest, but drops more small/distant faces |

The third panel isolates the effect of **input resolution**: `det_480` uses the very
same SCRFD-500MF network as `det_500m`, just fed a 480Γ—480 letterbox instead of
640Γ—640, so any difference you see is purely down to input size (speed vs. reach on
small faces).

Each panel draws every detected face (bounding box + confidence) and its title bar
reports the **face count** and **inference time**; the 5-point landmark coordinates
for each face are listed as text below the panel.
CPU-only ONNX Runtime β€” runs on a free Hugging Face Space.

## How it works

1. The image is letterboxed to each model's input size (640Γ—640 for `det_500m` /
   `det_2.5g`, 480Γ—480 for `det_480`), aspect ratio preserved.
2. All three SCRFD models run in ONNX Runtime (CPU).
3. `scrfd.py` decodes the anchor-based outputs (3 strides Γ— {score, bbox, kps}),
   applies IoU-NMS, and maps boxes back to the original image.

`scrfd.py` is a self-contained re-implementation of InsightFace's SCRFD
post-processing, so the raw `.onnx` files load directly β€” no `insightface`
package or model-pack directory needed.

## Run locally

```bash
pip install -r requirements.txt
python app.py
```

Then open the URL shown in the terminal (e.g. http://127.0.0.1:7860).

## Models

`det_500m.onnx` and `det_2.5g.onnx` are the standard InsightFace SCRFD detection
checkpoints (both with 5-point landmarks). `det_480.onnx` is the same SCRFD-500MF
network re-exported with a fixed 480Γ—480 input. They live in `models/`.