Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘€ Real-Time Face Detection and Recognition using YOLOv8

Python YOLOv8 OpenCV Streamlit License

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.


πŸ“Œ Project Highlights

  • βœ… 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

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_faces directory.

Image Size

640 Γ— 640

🧠 Face Recognition Pipeline

Live Camera / Image

↓

YOLOv8 Face Detection

↓

Extract Face Region

↓

Compare Against Faces in "known_faces"

↓

Recognized Person
        or
Unknown Person

↓

Display Bounding Box + Name

πŸ—οΈ Model Information

Component Value
Model YOLOv8s
Framework Ultralytics YOLO
Task Face Detection
Input Size 640 Γ— 640
Deployment OpenCV + Streamlit

βš™οΈ Training Configuration

Parameter Value
Framework Ultralytics YOLOv8
Model YOLOv8s
Image Size 640
Hardware Kaggle NVIDIA Tesla T4 GPU
Epochs 100
Batch Size 32

πŸ“Š Model Performance

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.


⚑ Inference Performance

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.


πŸ–₯️ Applications

This repository includes two different applications for real-time face detection and recognition.

1. OpenCV Desktop Application (Recommended)

The desktop application is optimized for speed and real-time performance.

Features

  • 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.py

2. Streamlit Web Application

The Streamlit application provides a clean browser-based interface for demonstrations and interactive usage.

Features

  • Browser-based interface
  • Real-time webcam support
  • Face recognition
  • Easy to use
  • Interactive controls

Run the Streamlit application:

streamlit run app.py

πŸ“Έ Application Screenshots

OpenCV Desktop Application

Desktop


Streamlit Web Application

Streamlit


YOLOv8 Detection Results

Prediction


πŸ› οΈ Technologies Used

  • Python
  • Ultralytics YOLOv8
  • OpenCV
  • Streamlit
  • NumPy
  • Pillow
  • face_recognition

πŸ“ Repository Structure

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


▢️ Installation

Clone the repository:

git clone https://github.com/SafiUrRehmanAi/YOLOv8-Face-Recognition.git

Navigate to the project directory:

cd YOLOv8-Face-Recognition

Install the required packages:

pip install -r requirements.txt

▢️ Usage

Run the OpenCV Desktop Application

python main.py

Run the Streamlit Web Application

streamlit run app.py

To recognize known individuals, simply place their images inside the known_faces folder before launching the application.


πŸš€ Future Improvements

  • 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)

πŸ“œ License

This project is licensed under the MIT License.

About

Real-time face detection and recognition using YOLOv8, OpenCV, and Streamlit.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages