Skip to content

Qengineering/TensorFlow_Lite_Face_Mask_Jetson-Nano

Repository files navigation

TensorFlow_Lite_Face_Mask_Jetson-Nano

output image

TensorFlow Lite Face Mask detection running on a Jetson Nano

License

A fast C++ implementation of TensorFlow Lite Face Mask detector on a Jetson Nano.
Once overclocked to 2015 MHz, the app runs at 14 FPS.

You could call this Face Mask detection 2.0.
The network used is a re-trained MobileNet V2 SSD. It has three classes: no maks, a mask, and wearing a mask incorrectly. Although the latter category is not very convincing, given the small size of training samples.
It's not the usual cascade of the two deep learning models, one face recognition and a second one that detects the masks.
This one model now recognizes not only the white masks, but also the black, colored and fancy masks.
Although it can detect more faces/masks in the same scene, the best result is still one face in front of the camera.


Benchmark.

Model CPU 2015 MHz CPU 1479 MHz RPi 4 64os 1950 MHz
ssd_mobilenet_v2.tflite 14.0 FPS 11.4 FPS 8.1 FPS
ssd_mobilenet_v2_fpnlite.tflite 10.8 FPS 8.5 FPS 6.3 FPS

Special made for a Jetson Nano see Q-engineering deep learning examples


Dependencies.

To run the application, you have to:


Running the app.

To extract and run the network in Code::Blocks
$ mkdir MyDir
$ cd MyDir
$ wget https://github.com/Qengineering/TensorFlow_Lite_Face_Mask_Jetson-Nano/archive/refs/heads/main.zip
$ unzip -j master.zip
Remove master.zip, LICENSE and README.md as they are no longer needed.
$ rm master.zip
$ rm README.md

Your MyDir folder must now look like this:
Face_Mask_Video.mp4
ssd_mobilenet_v2_fpnlite.tflite - more accurate
ssd_mobilenet_v2.tflite - somewhat faster
TestTensorFlow_Lite_Mask.cpb
FaceMask.cpp
Kapje_x.jpg - examples

Run TestTensorFlow_Lite.cpb with Code::Blocks.
You may need to adapt the specified library locations in TestTensorFlow_Lite.cpb to match your directory structure.


WebCam.

If you want to use a camera please alter line 130 in main.cpp to
cv::VideoCapture cap(0); //WebCam
If you want to run a movie please alter line 130 in main.cpp to
cv::VideoCapture cap("Face_Mask_Video.mp4"); //Movie


Thanks.

https://www.kaggle.com/andrewmvd/face-mask-detection
https://github.com/tanhouren/Face_mask_detector

output image
output image