The AntiSpoofingDetector is an advanced anti-spoofing/liveness detection system that leverages facial recognition technology. This project is implemented using Python and OpenCV, providing a robust solution to distinguish between real faces and spoof attempts.
-
Facial Recognition: The detector utilizes state-of-the-art facial recognition techniques to identify and authenticate real faces.
-
Liveness Detection: With the help of a trained model, the system assesses the liveness of detected faces to prevent spoofing attempts.
-
Python and OpenCV: The project is implemented in Python, a versatile and widely-used programming language, and employs the OpenCV library for computer vision tasks.
-
Trained Model: The AntiSpoofingDetector incorporates a pre-trained model, ensuring accurate and reliable performance in different scenarios.
To use the AntiSpoofingDetector, you need to install the following dependencies:
pip install opencv-python
pip install ultralytics
pip install mediapipe
If you have a compatible GPU and want to accelerate the system using CUDA, follow these steps:
-
Install the CUDA Toolkit: CUDA Toolkit Installation Guide.
-
Install PyTorch with GPU support: https://pytorch.org/get-started/locally/
To set up the Dataset
directory and its subdirectories for the AntiSpoofingDetector, follow these steps:
Open a terminal or command prompt and navigate to the root directory of the AntiSpoofingDetector project. Run the following command:
mkdir Dataset
Open a terminal or command prompt and navigate to the root directory of the AntiSpoofingDetector project. Run the following command:
mkdir Dataset/all
mkdir Dataset/DataCollect
mkdir Dataset/Fake
mkdir Dataset/Real
mkdir Dataset/SplitData
If you choose to manually populate the dataset, consider adding real faces and fake faces to the Dataset/all
directory, aiming for an equal split of each.
Before proceeding, make sure to alter the classID
parameter in the dataCollection.py
file:
- Set
classID
to 0 for fake faces. - Set
classID
to 1 for real faces.
This adjustment ensures proper labeling during the data collection process.
Note: It's essential to maintain a balanced representation of real and fake faces in the Dataset/all
directory to enhance the performance and reliability of the AntiSpoofingDetector.
After making these changes, you can proceed with the data collection process as outlined in the project instructions.
The AntiSpoofingDetector relies on various archives for its functionality. Follow these steps to set up the necessary components:
Obtain the models archive file named models.zip
from the provided source.
Locate the downloaded models.zip
file in your file system.
- Right-click on the
models.zip
file. - Select "Extract All..." and choose the destination folder.
- Open a terminal.
- Navigate to the directory containing the
models.zip
file. - Run the following command:
unzip models.zip
By following these steps, you'll have successfully extracted the necessary components for the AntiSpoofingDetector, including the dataset, runs, and models. Adjust the instructions as needed for your specific project structure and user requirements.
To run the AntiSpoofingDetector, follow these steps:
- Open a terminal.
- Navigate to the directory containing
main.py
:cd /path/to/AntiSpoofingDetector
- Run the main script:
python main.py
- To quit press:
q
To train a new model, follow these steps:
- Navigate to the directory containing
train.py
:cd /path/to/AntiSpoofingDetector
- Run the training script:
python train.py
- After training, use the best model (
best.pt
) fromrun/detect/train/weights
and place it in themodels
folder. - Use the trained model in
main.py
for liveness detection.