Machine learning part of a fullstack application to tell if you're wearing a mask right
Followed ImageAI's prediction model
Used images from Kaggle:
- Clone this repository
- Install the pip dependencies listed below
- Download the latest model from the releases tab
- Place the
.h5
file intraining_data/models/
- Edit
test_model.py
'smodel
variable to match the filename - Place a test image (or use an included one) in
test_images/
- Edit
test_model.py
'stest_image
variable to match the filename - Run the code with
python ./test_model.py
We used two publicly available datasets from the website Kaggle. Two scripts (mmds_to_cropped.py
and fmdds_to_cropped.py
) cropped out the faces labelled in each dataset. check_images.py
made sure there was no corrupt data. Then we combined the processed images for both datasets into aggregate/
. Finally, we manually cut down each class into 270 images (limited in quantity by the improper
class) and used 220:50 train:test ratio, formatted in training_data/
using ImageAI's directory structure.
Converts the dataset from Kaggle's format to ImageAI's format
For an unknown reason, Pillow's Image.save
function in mmds_to_imageai.py
occasionally spits out unreadable data -- data that can't be parsed by Image.open
. For that reason, this script finds the invalid files and deletes them. Bye-bye!
Trains a simple prediction model based on ImageAI's Prediction class
Tests the model against real-world images
face-mask-detection-dataset/
annotations/
images/
medical-masks-dataset/
medical-masks-dataset/
labels/
images/
cropped/
mask/
mask_weared_incorrect/
none/
poor/
with_mask/
without_mask/
aggregate/
mask/
improper/
none/
training_data/
json/
model_class.json
logs/
models/
test/
mask/
none/
improper/
train/
mask/
none/
improper/
Note: you must use Python <3.8 (I recommend 3.7).
tensorflow<2
scipy<1.5
numpy
keras
opencv-python
pillow
imageai