This project aims to build a real-time face recognition system that can capture video streams from multiple cameras using RTSP protocol, analyze the video frames to detect faces, create bounding boxes around those faces and labeling thoses boxes with the person names.
Demonstration Environment:
The development pipeline for the face recognition system consists of several key steps, including model selection, data preprocessing, training, and deployment. The following is an overview of the pipeline:
Capturing Video Frames from Multiple Cameras using RTSP Protocol:
Model Selection:
insight-face-paddle
library developed by PaddlePaddle for face recognition.Face Detection Model Optimization:
Integration of Face Detection and Recognition:
insight-face-paddle
.Similarity Measurement:
Multithreading for Model Inference:
GPU Support:
This guide outlines the steps to set up the required Python environment and install the necessary packages for face recognition using PaddlePaddle. Follow the instructions below to get started:
To begin, create a Python virtual environment using Python 3.8. Make sure you have pip version 20.0.2 installed. Run the following commands:
python3.8 -m venv myenv # Replace `myenv` with your preferred environment name
source myenv/bin/activate # Activate the virtual environment
Next, we need to install the PaddlePaddle framework. We'll be using version 2.4.2 with cpu support. Use the following command:
python -m pip install paddlepaddle==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
If you do have the gpu support you need to install the gpu version. You can find the command here selecting your cuda version here.
Install the Wheel package using pip:
pip install wheel
We will be using the InsightFacePaddle package for face recognition repository. Build the wheel package from this repository customized version of insight-face-paddle module.
Install it using the following commands:
git clone <this repository>
cd insight-face-paddle
python setup.py bdist_wheel
pip install dist/*
PaddlePaddle Hub is a powerful toolkit for pretrained AI models based on paddle paddle framework. Install it using the following command: Documentation
pip install paddlehub==2.1.0
To verify the installation, run the following code snippet:
import paddlehub
paddlehub.server_check()
For face detection, we'll use the PyramidBox Lite Mobile module from PaddleHub. PyramidBox is a one-stage face detector based on SSD. This model has solid robustness against interferences such as light and scale variation. This module is optimized for mobile device, based on PyramidBox, trained on WIDER FACE Dataset and Baidu Face Dataset. Documentation
Install it using the following command:
hub install pyramidbox_lite_mobile
You have now completed the setup process for face recognition using PaddlePaddle. Follow the next steps specific to your application to continue. Feel free to refer to the provided links for further documentation on each component.
Before proceeding, make sure you have activated the Python virtual environment you created earlier. Run the following command:
source myenv/bin/activate # Replace `myenv` with your virtual environment name
First you will need to introduce the people to the model
Run the enroll_new_faces.py
script to enroll new people's faces.
camera_url
variable in the script.index.bin
file.Run the script using the following command:
(myenv)akash@akash:~$ python enroll_new_faces.py
You will need to provide rtsp links for the cameras which will be streaming.
In the file camera_urls.json
you need to paste the rtsp links in a list.
akash@akash:~$ cat camera_urls.json
["rtsp://192.168.0.100:8080/h264_pcm.sdp","rtsp://192.168.0.103:8080/h264_pcm.sdp"]
If you want to use the cpu environment you can specify the no. of threads the model will be using during inference time in the script args.cpu_threads
changing this variable value.
Run the cpu script using the following command:
(myenv)akash@akash:~$ python face_recognition-cpu.py
Also if you have gpu support you can run the script for gpu version
(myenv)akash@akash:~$ python face_recognition-gpu.py