A professional, real-time face detection system built with YOLOv12 and Flask. This project leverages the latest Attention Mechanism features of YOLOv12 to detect faces in images, videos, and live webcam streams with state-of-the-art accuracy and speed.
View the demo using this link.
- Upload and detect faces in images (JPG, PNG) and videos (MP4, AVI, MOV).
- Attention-based detection for small, distant, or occluded faces.
- Interactive bounding boxes with cropped face previews.
- Download annotated results and face statistics.
- Real-time detection directly from your browser.
- Side-by-side video feed and detection results.
- Live statistics (FPS, face count, duration).
- Built-in MySQL database integration (via Aiven) to collect user ratings and feedback securely.
- Ready for admin dashboard visualization.
- YOLOv12 Nano (yolov12n-face.pt) - Super Fast, best for CPU/Webcam.
- YOLOv12 Small (yolov12s-face.pt) - Balanced speed & accuracy.
- YOLOv12 Medium (yolov12m-face.pt) - High precision (The "Sweet Spot").
- YOLOv12 Large (yolov12l-face.pt) - State-of-the-art accuracy for high-res images.
graph TD
%% Define Nodes
User((User))
UI[Web UI / Frontend]
ModelSelection{Select YOLOv12 Model}
InputSelect{Select Data Source}
%% Data Sources
Upload[Upload Image/Video]
Webcam[Live Webcam Stream]
%% Backend & API
API_Detect[/API: /api/detect-image & video/]
FlaskBackend[Flask Backend Server]
YOLO_Engine[YOLOv12 Inference Engine]
%% Results & Post-processing
Results[Extract Bounding Box, Confidence, Count]
Display[Display Results & Stats on UI]
%% Actions & Telemetry
Action_Download[Download Annotated Files]
Action_Feedback[Submit Rating & Feedback]
API_Download[/API: /api/download/]
API_Feedback[/API: /api/feedback/]
DB[(Aiven MySQL Database)]
%% Edges (Flow)
User --> UI
UI --> ModelSelection
ModelSelection -->|Nano / Small / Medium / Large| InputSelect
InputSelect -->|Static File| Upload
InputSelect -->|Real-time| Webcam
Upload --> API_Detect
API_Detect --> FlaskBackend
FlaskBackend --> |Save temporary file to UPLOAD_FOLDER| YOLO_Engine
Webcam --> |Send continuous frames| YOLO_Engine
YOLO_Engine --> Results
Results --> Display
Display --> Action_Download
Display --> Action_Feedback
Action_Download --> API_Download
Action_Feedback --> API_Feedback
API_Feedback --> |Securely store telemetry| DB
1. Initialization & Configuration
- User Interaction: The user accesses the Web UI (hosted locally or via Hugging Face Spaces).
- Model Selection: The system prompts the user to select a YOLOv12 model variant (Nano, Small, Medium, or Large). This allows the user to balance between blazing-fast inference speeds (ideal for webcams) and maximum precision (ideal for high-resolution static images).
2. Data Input Stage The system routes the user through one of two primary data pipelines:
- Batch Processing (Static Files): The user uploads image (JPG, PNG) or video (MP4, AVI, MOV) files. The frontend packages the payload and sends a POST request to the respective
/api/detect-imageor/api/detect-videoendpoints. - Real-Time Stream: The user grants browser camera permissions. The frontend captures the live video feed and continuously pushes frames to the processing engine.
3. Core AI Inference
- Request Handling: The Flask Backend receives the data. For uploads, it temporarily stores the files in the
UPLOAD_FOLDER(validating against theMAX_FILE_SIZElimit). - YOLOv12 Processing: The YOLOv12 Inference Engine is triggered. Utilizing its advanced Attention Mechanisms, it scans the input to detect human faces, calculating exact bounding box coordinates and assigning a Confidence Score based on the pre-configured threshold (default:
0.32).
4. Post-Processing & Response
- Data Aggregation: The raw model outputs are synthesized into a structured JSON response (containing face count, coordinates, and inference duration) and returned to the client.
- Visualization: The Web UI dynamically renders interactive bounding boxes over the media and updates real-time statistics (such as FPS and total faces detected).
5. User Actions & Telemetry
- Retrieval: Users can interact with the
/api/download/<filename>endpoint to securely download their processed, annotated files. - Feedback Loop: To drive future improvements, users can submit ratings and comments. The frontend calls the /api/feedback endpoint, which securely inserts the telemetry data into the Aiven MySQL Database for future analytics.
- Python 3.10+
- Git
- Clone the repository:
git clone [https://github.com/RevDra/human-face-detection.git](https://github.com/RevDra/human-face-detection.git)
cd human-face-detection- Install dependencies:
pip install -r requirements.txt- Environment Setup (Required): Copy the template environment file and add your secure credentials.
cp .env.example .envOpen .env in a text editor and update the DB_URL with your MySQL connection string.
- Run the web server:
./config/deploy.sh startconfig\deploy.bat start- Open in browser: Navigate to
https://localhost:7860
Human_face_detection/
βββ .github/ # CI/CD & Automation
β βββ ISSUE_TEMPLATE/ # Community Forms
β β βββ bug_report.md # Bug report template
β β βββ config.yml # Discussions link config
β β βββ feature_request.md # Feature request template
β βββ workflows/
β β βββ docker-publish.yml # Auto-build Docker Image
β β βββ lint.yml # Quality Check (Black + Flake8 + isort + Mypy)
β βββ dependabot.yml # Automated Dependency Updates
β βββ FUNDING.yml # Sponsor settings
β
βββ assets/ # Project Images & Screenshots
β βββ demo_ui.png # Interface preview for README
β
βββ config/ # Configuration & Deployment scripts
β βββ Dockerfile # Docker image config
β βββ docker-compose.yml # Docker Compose setup
β βββ deploy.sh # Linux deployment script
β βββ deploy.bat # Windows deployment script
β βββ DEPLOYMENT_GUIDE.md # Detailed deployment guide
β
βββ models/ # YOLOv12 Models
β βββ yolov12n-face.pt # Nano model (Fastest)
β βββ yolov12s-face.pt # Small model (Balanced)
β βββ MODELS.md # Download instructions for Med/Large models
β βββ training/ # Source code & benchmarks (Loss, PR curves, etc.)
β
βββ src/ # Source Code
β βββ web_app.py # Flask web server
β βββ face_detection_yolov12.py # YOLOv12 detection engine
β
βββ web/ # Frontend Assets
β βββ templates/
β βββ index.html # Web UI
β
βββ .flake8 # Flake8 Configuration
βββ .dockerignore # Docker Ignore
βββ .gitignore # Git Ignore
βββ .gitattributes # Normalized code (LF)
βββ pyproject.toml # Black + Mypy + isort Configuration
βββ CODE_OF_CONDUCT.md # Community guidelines
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # AGPL v3 License
βββ README.md # Main documentation
βββ SECURITY.md # Security policy
βββ .env.example # Template for environment variables (DB credentials)
βββ requirements.txt # Python dependencies
You can run the application instantly without needing to install Python or manually install dependencies.
Prerequisites: Docker Desktop installed.
- Clone the repository:
git clone [https://github.com/](https://github.com/)RevDra/human-face-detection.git
cd Human_face_detection- Run with Docker Compose:
# Build and run with Docker Compose (from project root)
docker-compose -f config/docker-compose.yml up --build
# Or build manually
docker build -t yolov12-face-detection -f config/Dockerfile .
docker run -p 7860:7860 -v $(pwd)/data:/app/data yolov12-face-detection- Access the App:
Open
http://localhost:7860in your browser.
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Web interface |
| POST | /api/detect-image |
Detect faces in uploaded image |
| POST | /api/detect-video |
Detect faces in uploaded video |
| GET | /api/models |
List available models |
| POST | /api/feedback |
Submit user rating and comments to database |
| GET | /api/health |
Health check |
| GET | /api/download/<filename> |
Download processed files |
- Select a detection model
- Upload an image/video or start webcam
- Wait for processing
- View results and download if needed
import requests
# Detect faces in image
with open('image.jpg', 'rb') as f:
files = {'file': f}
data = {'model': 'yolov12l-face.pt'}
response = requests.post('http://localhost:7860/api/detect-image',
files=files, data=data)
result = response.json()
print(f"Detected {result['detections']['count']} faces")Default: 0.32 (32%)
- Higher threshold = fewer false positives but may miss faces
- Lower threshold = more detections but more false positives
- Bounding box coordinates (x1, y1, x2, y2)
- Confidence score (0-100%)
- Face dimensions (width Γ height)
- Face position on image
Edit web_app.py to modify:
MAX_FILE_SIZE- Maximum upload size (default: 500MB)UPLOAD_FOLDER- Temporary file locationPORT- Application port (default: 7860)
Three model files are required in the models/ directory:
yolov12n-face.pt(5.3 MB) β Includedyolov12s-face.pt(18.5 MB) β Includedyolov12m_face.pt(39.8 MB) π₯ Downloadyolov12l_face.pt(52.3 MB) π₯ Download
See models/MODELS.md for detailed download instructions.
- Use YOLOv12 Nano for webcam to achieve high FPS.
- Use YOLOv12 Large for high-resolution static images.
- If running on Hugging Face Spaces (CPU), stick to Nano or Small models.
- Chrome/Edge: β Full support
- Firefox: β Full support
- Safari: β Full support
- IE: β Not supported
FileNotFoundError: Model not found: models/yolov12m-face.pt
Solution: Download missing models from models/MODELS.md. Only yolov12n-face.pt and yolov12s-face.pt are included by default.
Solution: Grant camera permission in browser settings. If deploying on a remote server, you must use HTTPS for the webcam to work.
Solution: Use a smaller model (Nano) or reduce video resolution
Solution:
- Use YOLOv12 Nano
- Reduce input resolution
- Check CPU/GPU usage
- Model Setup Guide - Download and setup instructions
- YOLOv12-Face Repository - Source of the models/weights.
- Ultralytics YOLOv12 - YOLOv12 documentation.
- Flask Documentation
- OpenCV Documentation
This project uses the following open-source components:
-
YOLOv12 by Ultralytics:
- License: AGPL-3.0
- Source: https://github.com/ultralytics/ultralytics
-
Face Detection Weights inspired by YapaLab:
- License: GPL-3.0
- Source: https://github.com/YapaLab/yolo-face
Project License: This entire project is licensed under the AGPL-3.0 to comply with the licensing terms of the YOLO ecosystem.
Last Updated: February 25, 2026 | Status: β Production Ready
