Skip to content

Qengineering/Face-Mask-Detection-Jetson-Nano

Repository files navigation

Face-Mask-Detection-Jetson-Nano

output image

A fast face mask recognition running at 44-5 FPS on a Jetson Nano.

License

This is a fast C++ implementation of two deep learning models found in the public domain.

The first is face detector of Linzaer running on a ncnn framework.
https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB.

The second is the Paddle Lite mask detection which classifies the found faces.
https://github.com/PaddlePaddle/Paddle-Lite/tree/develop/lite/demo/cxx/mask_detection.

The frame rate depends on the number of detected faces and can be calculated as follows:
FPS = 1.0/(0.022 + 0.008 x #Faces) when overclocked to 2014 MHz.

Paper: https://arxiv.org/abs/1905.00641.pdf
Size: 320x320

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

New version 2.0.

A new and superior version with only TensorFlow Lite for a Jetson Nano see GitHub

Dependencies.

April 4 2021: Adapted for ncnn version 20210322 or later

To run the application, you have to:

  • The Paddle Lite framework installed. Install Paddle
  • The Tencent ncnn framework installed. Install ncnn
  • Code::Blocks installed. ($ sudo apt-get install codeblocks)

Running the app.

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

Your MyDir folder must now look like this:
Face_1.jpg
Face_2.jpg
Face_3.jpg
Face_Mask_Video.mp4
mask_detector_opt2.nb
MaskUltra.cpb
mask_ultra.cpp
UltraFace.cpp
UltraFace.hpp
RFB-320.bin
RFB-320.param
slim_320.bin
slim_320.param

Notes.

The directories in the Code::Blocks project file will probably need to be adapted to the naming convention you are using.
The camera input used is a simple OpenCV webcam. The GStreamer is not used in this example for symplicity reasons.

The RFB-320 model recognizes slightly more faces than slim_320 at the expense of a little bit of speed. It is up to you.
Note that the compilation of the Paddle Lite framework in your application may take a while.

See the Raspberry Pi video at https://youtu.be/LDPXgJv3wAk