Face mask detection
This model is a lightweight face mask detection model. Based on ssd,the backbone is Mobilenet and RFB.
Key Features
- Tensorflow 2.1
- Trainging and Inference
- Precision with mAP
- Eager mode training with
tf.GradientTape
- Network function with
tf.keras
- Dataset prepocessing with
tf.data.TFRecordDataset
โโโ assets
โ โโโ 1_Handshaking_Handshaking_1_71.jpg
โ โโโ out_1_Handshaking_Handshaking_1_71.jpg
โ โโโ out_test_00002330.jpg
โ โโโ test_00002330.jpg
โโโ checkpoints
โ โโโ weights_epoch_100.h5
โโโ components
โ โโโ config.py
โ โโโ __init__.py
โ โโโ kmeans.py
โ โโโ prior_box.py
โ โโโ utils.py
โโโ dataset
โ โโโ check_dataset.py
โ โโโ tf_dataset_preprocess.py
โ โโโ train_mask.tfrecord
โ โโโ trainval_mask.tfrecord
โ โโโ val_mask.tfrecord
โ โโโ voc_to_tfrecord.py
โโโ inference.py
โโโ logs
โ โโโ train
โโโ mAP
โ โโโ compute_mAP.py
โ โโโ detection-results
โ โโโ detect.py
โ โโโ ground-truth
โ โโโ __init__.py
โ โโโ map-results
โ โโโ README.md
โโโ Maskdata
โ โโโ Annotations
โ โโโ ImageSets
โ โโโ Main
โ โ โโโ train.txt
โ โ โโโ trainval.txt
โ โ โโโ val.txt
โ โโโ JPEGImages
โโโ network
โ โโโ __init__.py
โ โโโ losses.py
โ โโโ model.py
โ โโโ net.py
โ โโโ network.py
โโโ README.md
โโโ train.py
โโโ requirements.txt
Usage
Installation
Create a new python virtual environment by Anaconda ,pip install -r requirements.txt
Data Preparing
-
Face Mask Data
Source data from AIZOOTech , which is a great job.
I checked and corrected some error to apply my own training network according to the voc dataset format. You can download it here:
- Baidu code:44pl
- GoogleDrive
-
Data Processing
-
Download the mask data images
-
Convert the training images and annotations to tfrecord file with the the script bellow.
python dataset/voc_to_tfrecord.py --dataset_path Maskdata/ --output_file dataset/train_mask.tfrecord --split train
you can change the --split parameters to 'val' to get the validation tfrecord, Please modify the inside setting
voc_to_tfrecord.py
for different situations.
-
-
Check tfrecord dataloader by run
python dataset/check_dataset.py
.
Training
-
Modify your configuration in
components/config.py
.You can get the anchors by run
python components/kmeans.py
-
Train the model by run
python train.py
.
Inference
-
Run on video
python inference.py --model_path checkpoints/ --camera True or python inference.py --model_path checkpoints/*.h5 --camera True
-
Detect on Image
python inference.py --model_path checkpoints/ --img_path assert/1_Handshaking_Handshaking_1_71.jpg
mAP
-
Convert xml to txt file on
mAP/ground truth
, predicting the bbox and class onmAP/detection-results
.python mAP/detect.py --model_path checkpoints/ --dataset_path Maskdata/ --split val python mAP/compute_mAP.py
For K210 project:
something refer to k210-camera-project.
Reference
- mAP code: https://github.com/Cartucho/mAP
- SSD-Tensorflow: https://github.com/balancap/SSD-Tensorflow
- ssd-tf2: https://github.com/ChunML/ssd-tf2