1- # mtcnn_facenet_cpp_tensorRT
1+ # Face Recognition for NVIDIA Jetson (Nano) using TensorRT
22Face recognition with [ Google FaceNet] ( https://arxiv.org/abs/1503.03832 )
33architecture and retrained model by David Sandberg
44([ github.com/davidsandberg/facenet] ( https://github.com/davidsandberg/facenet ) )
55using TensorRT and OpenCV. <br > This project is based on the
66implementation of l2norm helper functions which are needed in the output
77layer of the FaceNet model. Link to the repo:
8- [ github.com/r7vme/tensorrt_l2norm_helper] ( https://github.com/r7vme/tensorrt_l2norm_helper )
8+ [ github.com/r7vme/tensorrt_l2norm_helper] ( https://github.com/r7vme/tensorrt_l2norm_helper ) . <br >
9+ Moreover, this project uses an adapted version of [ PKUZHOU's implementation] ( https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT )
10+ of the mtCNN for face detection. More info below.
11+
912
1013## Dependencies
1114cuda 10.0 + cudnn 7.5 <br > TensorRT 5.1.x <br > OpenCV 3.x <br >
@@ -15,8 +18,8 @@ TensorFlow r1.14 (for Python to convert model from .pb to .uff)
1518#### 1. Install Cuda, CudNN, TensorRT, and TensorFlow for Python
1619You can check [ NVIDIA website] ( https://developer.nvidia.com/ ) for help.
1720Installation procedures are very well documented.<br ><br >** If you are
18- using NVIDIA Jetson AGX Xavier with Jetpack 4.2.2** , all needed packages
19- should be installed if the Xavier was correctly flashed using SDK
21+ using NVIDIA Jetson (Nano, TX1/2, Xavier) with Jetpack 4.2.2** , all needed packages
22+ should be installed if the Jetson was correctly flashed using SDK
2023Manager, you will only need to install cmake and openblas:
2124``` bash
2225sudo apt-get install cmake libopenblas-dev
@@ -31,8 +34,8 @@ trained or just used for inference. This switch layer cannot be
3134processed in TensorRT which is why it needs to be removed. Apparently
3235this can be done using freeze_graph from TensorFlow, but here is a link
3336to model where the phase train tensor has already been removed from the
34- saved model < br >
35- [ https://github.com/apollo-time/facenet/raw/master/model/resnet/facenet.pb ]
37+ saved model
38+ [ github.com/apollo-time/facenet/raw/master/model/resnet/facenet.pb ] ( https://github.com/apollo-time/facenet/raw/master/model/resnet/facenet.pb )
3639
3740#### 3. Convert frozen protobuf (.pb) model to UFF
3841Use the convert-to-uff tool which is installed with tensorflow
@@ -43,50 +46,75 @@ Please check the file for the user defined values and update them if
4346needed. Do not worry if there are a few warnings about the
4447TRT_L2NORM_HELPER plugin.
4548``` bash
46- cd / path/to/project
49+ cd path/to/project
4750python3 step01_pb_to_uff.py
4851```
4952You should now have a facenet.uff (or similar) file which will be used
50- as the input model to TensorRT.
53+ as the input model to TensorRT. <br >
54+ The path to model is hardcoded, so please put the __ facenet.uff__ in the
55+ [ facenetModels] ( ./facenetModels ) directory.
56+
57+
58+ #### 4. Get mtCNN models
59+ This repo uses an [ implementation by PKUZHOU] ( https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT )
60+ of the [ multi-task Cascaded Convolutional Neural Network (mtCNN)] ( https://arxiv.org/pdf/1604.02878.pdf )
61+ for face detection. The original implementation was adapted to return the bounding boxes such that it
62+ can be used as input to my FaceNet TensorRT implementation.
63+ You will need all models from the repo in the [ mtCNNModels] ( ./mtCNNModels ) folder so please do this
64+ to download them:
65+ ``` bash
66+ cd path/to/project/mtCNNModels
67+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det1_relu.caffemodel
68+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det1_relu.prototxt
69+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det2_relu.caffemodel
70+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det2_relu.prototxt
71+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det3_relu.caffemodel
72+ wget https://github.com/PKUZHOU/MTCNN_FaceDetection_TensorRT/blob/master/det3_relu.prototxt
73+ ```
74+ Done you are ready to build the project!
5175
52- #### 4 . Build the project
53- WARNING: This step might take a while when done the first time. TensorRT
76+ #### 5 . Build the project
77+ _ NOTE: _ This step might take a while when done the first time. TensorRT
5478now parses and serializes the model from .uff to a runtime engine
5579(.engine file).
5680``` bash
5781mkdir build && cd build
58- cmake \
59- -DCMAKE_BUILD_TYPE=Release \
60- -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0/ \
61- -DTENSORRT_ROOT=/usr/ ..
82+ cmake -DCMAKE_BUILD_TYPE=Release ..
6283make -j${nproc}
6384```
64- If ** not** run on Xavier update the path to your TensorRT installation.
85+ If ** not** run on Jetson platform set the path to your CUDA and TensorRT installation
86+ using _ -DCUDA_TOOLKIT_ROOTDIR=path/to/cuda_ and _ -DTENSORRT_ROOT=path/to/tensorRT_ .
6587
6688## NOTE
6789** .uff and .engine files are GPU specific** , so if you use want to run
6890this project on a different GPU or on another machine, always start over
6991at step ** 3.** above.
7092
7193## Usage
72-
94+ Put images of people in the imgs folder. Please only use images that contain one face.<br >
95+ ** NEW FEATURE** : You can now add faces while the algorithm is running. When you see
96+ the OpenCV GUI, press "** N** " on your keyboard to add a new face. The camera input will stop until
97+ you have opened your terminal and put in the name of the person you want to add.
7398``` bash
7499./mtcnn_facenet_cpp_tensorRT
75100```
101+ Press "** Q** " to quit and to show the stats (fps).
76102
103+ ## Performance
104+ Performance on ** NVIDIA Jetson Nano**
105+ * ~ 60ms +/- 20ms for face detection using mtCNN
106+ * ~ 22ms +/- 2ms per face for facenet inference
107+ * ** Total:** ~ 15fps
77108
78- ## Notes
79- ** Performance** on NVIDIA Jetson Xavier:
109+ Performance on ** NVIDIA Jetson AGX Xavier** :
80110* ~ 40ms +/- 20ms for mtCNN
81- * ~ 9ms +/- 1ms per face for inference of facenet <br ><br > ** TOTAL:**
82- ~ 22fps with ~ 13% GPU usage
83-
84- ## ToDo
85- *
86- * how to get acquainted to new people while algorithm is running
87- * database of embeddings not the actual pictures
111+ * ~ 9ms +/- 1ms per face for inference of facenet
112+ * ** Total:** ~ 22fps
113+
114+ ## License
115+ Please respect all licenses of OpenCV and the data the machine learning models (mtCNN and Google FaceNet)
116+ were trained on.
88117
89118## Info
90119Niclas Wesemann <br >
91- [ niclas.wesemann@gmail.com ] ( mailto:niclas.wesemann@gmail.com ) <br >
92- August 2019
120+ [ niclaswesemann@gmail.com ] ( mailto:niclas.wesemann@gmail.com ) <br >
0 commit comments