CV / RetinaFace

RetinaFace

The current service loads the MobileNet-backbone model and exposes confidence filtering through its API.

4 downloads
Precision
RKNN

Choose the device you're using, the set up guide and documentation will update accordingly.

Getting Started

Deploy
sudo docker run --rm --privileged --net=host -e RKNN_LOG_LEVEL=0 \
  --device /dev/dri/renderD129:/dev/dri/renderD129 \
  -v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
  ghcr.io/seeed-projects/recomputer-rk-cv/rk3576-retinaface:latest \
  python web_service.py --platform rk3576 --model_dir /app/model --camera_id -1 --host 0.0.0.0 --port 8000

REST API

Use the REST API to run inference. Copy the commands below.

Curl
curl http://localhost:8080/v1/chat/completions -d '{
  "model": "retinaface-rknn",
  "messages": [{"role": "user", "content": "Hello"}]
}'
Python
import requests

resp = requests.post(
    "http://localhost:8080/v1/chat/completions",
    json={"model": "retinaface-rknn", "messages": [{"role": "user", "content": "Hello"}]},
)
print(resp.json())

Model Details

RetinaFace on reComputer RK3576 and RK3588

This page documents the RetinaFace service in reComputer-RK-CV. It detects faces and five facial landmarks with RKNN acceleration and provides image, camera, local-video, and uploaded-video modes.

Model information

PropertyValue
Active modelmodel/retinaface_mobile.rknn
Packaged alternativemodel/retinaface_resnet50.rknn
Input320 x 320 letterboxed RGB
OutputFace box, confidence, and five landmarks
NMSFixed IoU threshold of 0.5

Run the service

RK3576

bash
sudo docker run --rm --privileged --net=host \
  -e PYTHONUNBUFFERED=1 -e RKNN_LOG_LEVEL=0 \
  --device /dev/dri/renderD129:/dev/dri/renderD129 \
  -v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
  ghcr.io/seeed-projects/recomputer-rk-cv/rk3576-retinaface:latest \
  python web_service.py --platform rk3576 --model_dir /app/model \
  --camera_id -1 --host 0.0.0.0 --port 8000

RK3588

bash
sudo docker run --rm --privileged --net=host \
  -e PYTHONUNBUFFERED=1 -e RKNN_LOG_LEVEL=0 \
  --device /dev/dri/renderD129:/dev/dri/renderD129 \
  -v /proc/device-tree/compatible:/proc/device-tree/compatible:ro \
  ghcr.io/seeed-projects/recomputer-rk-cv/rk3588-retinaface:latest \
  python web_service.py --platform rk3588 --model_dir /app/model \
  --camera_id -1 --host 0.0.0.0 --port 8000

Open http://<BOARD_IP>:8000 or /docs. Map /dev/videoN and use --camera_id N for a camera, or pass --video video/test.mp4 for local video.

Startup arguments

ArgumentDefaultDescription
--platformRequiredrk3576 or rk3588.
--model_dirmodelRetinaFace RKNN files and test.jpg.
--camera_id-1Camera index; -1 disables capture.
--video, --video_pathNoneLooping local video; overrides the camera.
--host / --port0.0.0.0 / 8000Service address and port.

RKNN_LOG_LEVEL=0 hides confirmed harmless static-shape initialization messages. Remove it when diagnosing RKNN startup.

REST API

Endpoint: POST /api/models/retinaface/predict

bash
curl -X POST "http://<BOARD_IP>:8000/api/models/retinaface/predict" \
  -F "file=@test.jpg" -F "threshold=0.5"

Each result includes confidence, box as [x1,y1,x2,y2], and five landmarks. Update the preview/video threshold with POST /api/config and JSON such as {"threshold":0.5}.

Example response fields:

json
{
  "success": true,
  "model": "retinaface",
  "result": {
    "count": 1,
    "faces": [
      {
        "confidence": 0.96,
        "box": [120, 80, 310, 290],
        "landmarks": [[166, 145], [255, 144], [210, 190], [176, 232], [247, 231]]
      }
    ]
  }
}

The generic topk configuration field is reserved for service compatibility and is not used. NMS uses a fixed IoU threshold of 0.5.

EndpointPurpose
GET /api/healthPlatform, model names, and readiness.
GET /api/video_feedLatest face boxes and landmarks as MJPEG.
POST /api/video/uploadUpload an MP4.
POST /api/video/analyzeAnalyze an uploaded filename.
GET /api/video/statusProgress and errors.
GET /api/video/listUploaded and generated MP4 files.
GET /api/video/download/{filename}Download a result.

The upstream constructor currently loads retinaface_mobile.rknn explicitly. Using retinaface_resnet50.rknn requires changing task_runtime.py and verifying the same three-output layout; it cannot be selected only by a Docker command parameter. Frames are letterboxed to 320 x 320, converted from BGR to RGB, decoded with prior boxes and five landmarks, restored to source-image coordinates, filtered by confidence, and processed with NMS.

Build locally

bash
docker build -f docker/rk3576/retinaface.dockerfile \
  -t rk3576-retinaface:local src/rk3576_retinaface

docker build -f docker/rk3588/retinaface.dockerfile \
  -t rk3588-retinaface:local src/rk3588_retinaface

Inputs and Outputs

Input: image, video frame, or camera frame. Output: face boxes, confidence scores, and five landmarks.