File size: 2,261 Bytes
54fa0c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# Face Mask Detection


Detecting face mask with OpenCV and TensorFlow. Using simple CNN or model provided by TensorFlow as MobileNetV2, VGG16, Xception.

## Data
Raw data collected from kaggle and script `crawl_image.py`, split to 'Mask' and 'Non Mask' class.
Using `build_data.py` to extract faces from raw dataset and resize to 64x64.
## Installation
Clone the repo
```
git clone [email protected]:ksvbka/face-mask-detector.git
```
cd to project folder and create virtual env
```
virtualenv .env
source .env/bin/activate
pip install -r requirements.txt
```
Download raw dataset and execute script build_dataset.py to preprare dataset for training
```
cd data
bash download_data.sh
cd -
python3 build_dataset.py --data-dir data/dataset_raw/ --output-dir data/64x64_dataset
```
## Training
Execute `train.py` script and pass network architecture type dataset dir and epochs to it.
Default network type is MobileNetV2.
```
python3 train.py --net-type MobileNetV2 --data-dir data/64x64_dataset --epochs 20
```
View tensorboard
```
tensorboard --logdir logs --bind_all
```
## Testing
```
python3 mask_detect_image.py -m results/MobileNetV2-size-64-bs-32-lr-0.0001.h5 -i demo_image/2.jpg
```
## Result
Hyperparameter:
- batch size: 32
- Learing rate: 0.0001
- Input size: 64x64x3
Model result
| Model | Test Accuracy| Size | Params | Memory consumption|
| ------------- | -------------|-------------|-----------|-------------------|
| CNN | 87.67% | 27.1MB | 2,203,557 | 72.58 MB
| VGG16 | 93.08% | 62.4MB | **288,357** | **18.06 MB**
| MobileNetV2 (fine tune) | 97.33% | **20.8MB** | 1,094,373 | 226.67 MB
| **Xception** | **98.33%** | 96.6MB | 1,074,789 | 368.18 MB
Download pre-trained model: [link](https://drive.google.com/u/0/uc?id=1fvoIX1cz3O8yF3VNfneoM0AK7bR5ok7T&export=download)
## Demo
Using MobileNetV2 model









|