This project is a real-time face liveness detection system designed to distinguish between live faces and spoofed faces (e.g., from a photo or video). It uses a YOLOv8 model trained to classify faces as either "real" or "fake," providing an essential layer of security for facial recognition systems.
- Directory Structure
- Project Title and Description
- Table of Contents
- Installation Instructions
- Usage Guide
- Features
├── main.py
├── train.py
├── splitData.py
├── dataCollection.py
├── Dataset/
│ └── SplitData/
│ └── dataOffline.yaml
├── runs/
│ └── detect/
│ └── train/
│ ├── results.csv
│ └── args.yaml
├── Testing Scripts/
│ ├── yoloTest.py
│ └── faceDetectorTest.py
To get this project up and running, you'll need to have Python and pip installed. Then, follow these steps:
-
Clone the repository:
git clone [https://github.com/your-username/face-liveness-detection.git](https://github.com/your-username/face-liveness-detection.git) cd face-liveness-detection -
Install the required dependencies:
pip install opencv-python cvzone ultralytics
This project is divided into several scripts, each responsible for a specific part of the pipeline, from data collection to real-time detection.
This script is used to collect face images for training the model. You can collect images of "real" faces (by pointing the camera at yourself) and "fake" faces (by pointing the camera at a photo or video of a face).
- To collect images of fake faces, run the script with
classID = 0. - To collect images of real faces, change
classIDto1.
# In dataCollection.py
classID = 0 # 0 for fake, 1 for realRun the script from your terminal:
python dataCollection.pyAfter collecting the data, this script will split it into training, validation, and test sets. It will also create a dataOffline.yaml file, which is required for training the YOLOv8 model.
Run the script from your terminal:
python splitData.pyThis script trains the YOLOv8 model on the dataset you've prepared. The trained model will be saved in the runs/detect/train/ directory.
Run the script from your terminal:
python train.pyThis is the main script that runs the real-time face liveness detection. It uses the trained model to classify faces as "real" or "fake" and displays the results on the screen.
Run the script from your terminal:
python main.py- Real-Time Detection: The system processes video streams in real-time to detect and classify faces.
- High Accuracy: Utilizes the YOLOv8 model, known for its speed and accuracy in object detection tasks.
- Complete Pipeline: Provides a full pipeline from collecting data to training and deploying the model.
- Spoofing Prevention: Designed to prevent spoofing attacks in facial recognition systems, enhancing security.