Skip to content

Qengineering/TensorFlow_Lite_Face_Mask_RPi_64-bits

Repository files navigation

output image Find this example on our SD-image

TensorFlow_Lite_Face_Mask_RPi_64-bits

output image

TensorFlow Lite Face Mask detection running on a bare Raspberry Pi 4.

License

A fast C++ implementation of TensorFlow Lite Face Mask detector on a bare Raspberry Pi 4 with a 32 or 64-bit operating system. Ubuntu 18.04, or Ubuntu20.04 are also possible.
Once overclocked to 1900 MHz, your app runs at 8.3 FPS without any hardware accelerator.

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.

Update 8-29-2022.

  • Added GPIO outputs.

Benchmark.

Model RPi 4 64os 1900 MHz RPi 4 64os 1500 MHz
ssd_mobilenet_v2.tflite 8.1 FPS 7.5 FPS
ssd_mobilenet_v2_fpnlite.tflite 6.3 FPS 5.8 FPS

Special made for a Raspberry Pi 4 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_RPi_64-bits/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.


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


paypal

output image
output image
output image