A lightweight, fast face counting API using OpenCV DNN. Returns the number of faces detected in an image.
Built for speed and low resource usage - ideal for serverless deployments.
- 🚀 Fast inference (~50ms per image)
- 💾 Low memory footprint (~200MB)
- 🐳 Docker ready
- ☁️ DigitalOcean Functions compatible
- 🔧 Simple JSON API
# Build
docker build -t face-count-api-lite .
# Run
docker run -p 8000:8000 face-count-api-lite
# Test
curl -X POST http://localhost:8000/count-faces -F "file=@photo.jpg"
# {"face_count": 2}python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reloadUpload an image and get the face count.
curl -X POST http://localhost:8000/count-faces \
-F "file=@image.jpg"Response:
{"face_count": 3}curl http://localhost:8000/healthResponse:
{
"status": "healthy",
"model": "opencv-dnn-resnet10-ssd",
"model_loaded": true
}- Fork this repo
- Connect to DO App Platform
- Deploy from Dockerfile
doctl serverless install
doctl serverless connect
doctl serverless deploy .Uses OpenCV's pre-trained face detector:
- Architecture: ResNet-10 SSD
- Input size: 300x300
- Model size: ~10MB
| Metric | Value |
|---|---|
| Inference time | ~50ms |
| Memory usage | ~200MB |
| Cold start | ~2s |
- Optimized for frontal faces
- May miss small or distant faces in group photos
- For higher accuracy with complex scenes, consider MTCNN-based solutions
MIT
Contributions welcome! Please open an issue or PR.