Face mask detector for COVID-19 monitoring implemented on a Jetson Nano. The entire framework performs real-time at a 7 Hz. Any type of webcams or videostreams are available.
- tensorflow: 1.15.x
- keras
- imutils
- numpy
- opencv-python
This detection framework consists of two components:
- MTCNN based on TensorRT: It detects face in the given image.
- Publich CNN based model: It performs classification on the detected faces based on whether or not a mask is present. The output of the model is probability between 0 to 1 (softmax layer). In this repository, I also provide an instruction to convert this model to TensorRT format. Note that the TensorRT model must be built on the exact hardware you are going to use!
Go to convert_to_trt and follow the steps below:
from tensorflow import keras
model = keras.models.load_model("mask_detector.model")
model.save("mask_detector.h5")
pip3 install docopt
python3 freeze_h5_to_pb.py --model="mask_detector.h5" --output="mask_detector.pb"
Run "convert-to-uff.py" in the directory '/usr/lib/python3.?/dist-packages/uff/bin':
python3 convert-to-uff.py {$ pb file directory}
Then, 'mask_detector.uff' will be created in the current directory.
At the first time you run this uff file, it will serialize it to the tensorrt format. From the next time, it will automatically deserialize the tensorrt model.
| You should follow the steps above to convert plain CNN model to a TensorRT model. On the other hand, this repository in current form also supports vanilla inference with the plain model.
git clone <link-to-this-repository>
cd jetson_nano_face_mask_detector
python face_mask_detector.py
I analyzed the inference performance of the compared methods:
- Vanilla MTCNN + vanilla classification model.
- TensorRT MTCNN + vanilla classification model.
- TensorRT MTCNN + TensorRT classification model.
- Cythonizing python scripts with option 3.
This repository was inspired by the project of MTCNN TensorRT.