A real-time face detection and recognition system built using YOLOv8, OpenCV, and Streamlit. The project combines a custom-trained YOLOv8 face detector with real-time face recognition using a local database of known individuals. It provides both a lightweight desktop application for fast inference and a Streamlit web application for an interactive user experience.
- β Custom-trained YOLOv8s face detection model
- β Real-time face recognition using a local face database
- β Fast OpenCV desktop application
- β Interactive Streamlit web application
- β Live webcam face detection and recognition
- β Automatic recognition of registered individuals
- β Unknown face detection
- β High detection precision and recall
- β Lightweight and optimized for real-time inference
- β Trained on Kaggle using NVIDIA Tesla T4 GPU
Dataset: Face Detection Dataset (Roboflow Universe)
The YOLOv8s model was trained using a publicly available face detection dataset from Roboflow Universe, which contains annotated facial bounding boxes for object detection.
Note: This dataset is used only for face detection training. Face recognition is performed separately by comparing detected faces against images stored in the
known_facesdirectory.
640 Γ 640
Live Camera / Image
β
YOLOv8 Face Detection
β
Extract Face Region
β
Compare Against Faces in "known_faces"
β
Recognized Person
or
Unknown Person
β
Display Bounding Box + Name
| Component | Value |
|---|---|
| Model | YOLOv8s |
| Framework | Ultralytics YOLO |
| Task | Face Detection |
| Input Size | 640 Γ 640 |
| Deployment | OpenCV + Streamlit |
| Parameter | Value |
|---|---|
| Framework | Ultralytics YOLOv8 |
| Model | YOLOv8s |
| Image Size | 640 |
| Hardware | Kaggle NVIDIA Tesla T4 GPU |
| Epochs | 100 |
| Batch Size | 32 |
| Metric | Score |
|---|---|
| Precision | 0.991 |
| Recall | 0.959 |
| mAP@50 | 0.985 |
| mAP@50-95 | 0.793 |
The custom-trained YOLOv8s model achieved excellent detection performance while maintaining fast inference suitable for real-time face detection applications.
Example prediction:
Image Size : 640 Γ 640
Inference Time : 16.1 ms
Detected Faces : 2
The optimized model delivers smooth real-time performance, making it suitable for live webcam applications.
This repository includes two different applications for real-time face detection and recognition.
The desktop application is optimized for speed and real-time performance.
- Live webcam detection
- Real-time face recognition
- Bounding boxes
- Person name display
- Unknown face detection
- Lightweight and responsive
- Recommended for everyday use
Run the desktop application:
python main.pyThe Streamlit application provides a clean browser-based interface for demonstrations and interactive usage.
- Browser-based interface
- Real-time webcam support
- Face recognition
- Easy to use
- Interactive controls
Run the Streamlit application:
streamlit run app.py- Python
- Ultralytics YOLOv8
- OpenCV
- Streamlit
- NumPy
- Pillow
- face_recognition
YOLOv8-Face-Recognition/
β
βββ app.py # Streamlit application
βββ main.py # OpenCV desktop application
βββ train_yolo.ipynb
βββ README.md
βββ requirements.txt
βββ LICENSE
β
βββ known_faces/
β
βββ weights/
β βββ best.pt
β
βββ images/
β βββ opencv_app.png
β βββ streamlit_app.png
β βββ predictions.png
Clone the repository:
git clone https://github.com/SafiUrRehmanAi/YOLOv8-Face-Recognition.gitNavigate to the project directory:
cd YOLOv8-Face-RecognitionInstall the required packages:
pip install -r requirements.txtpython main.pystreamlit run app.pyTo recognize known individuals, simply place their images inside the known_faces folder before launching the application.
- Add support for video file inference
- Face registration directly from the application
- Face tracking for smoother real-time recognition
- Cloud deployment for remote access
- Optimize inference for edge devices
- Support multiple YOLO model variants (YOLOv8n, YOLOv8m, YOLO11)
This project is licensed under the MIT License.


