--- 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/`.