Face Mask Detection using PyTorch
A simple Face Mask Detection Model created using PyTorch and OpenCV.
📃 Installation
- Clone the repo
$ git clone https://github.com/rakshit087/facemaskDetectorPytorch.git
- Now, cd the cloned repo and install the dependencies by (You can use virtualenv for this purpose)
cd /YOUR_PATH/facemaskDetectorPytorch
$ pip3 install -r requirements.txt
💻 Usage
$cd /YOUR_PATH/facemaskDetectorPytorch/Face_Extractor
$python app.py
.Train_Model
├── data # your dataset folder
│ ├── train # to train your data
│ ├── mask
│ └── no_mask
│ └── test # to test your model
│ ├── mask
│ └── no_mask
└── Train_Model.py
After creating the dataset you can train your model by using 'Train_Model.py', after training the model, if you are satisfied by the results you can save the model when asked. The trained model will be saved in the same directory.
$cd /YOUR_PATH/facemaskDetectorPytorch/Train_Model
$python Train_Model.py
$cd /YOUR_PATH/facemaskDetectorPytorch/Use_Model
$python faceDetect.py
📁 Dataset Used
I created a custom dataset by mixing images from various sources.
🧠 Model Details
The model used Transfer Learning using MobileNetv2 (The parameters were freezed) as the base and I changed the classifier to -
Linear Layer (input - 1280 | output - 256 | Activation - ReLU)
⬇️
Linear Layer (input - 256 | output - 128 | Activation - ReLU | Dropout = 0.4)
⬇️
Linear Layer (input - 128 | output - 64 | Activation - ReLU)
⬇️
Linear Layer (input - 64 | output - 32 | Activation - ReLU | Dropout = 0.4)
⬇️
Linear Layer (input - 32 | output - 2 | Activation - SoftMax)
⚠️ Issues and Limitations
💜 Thank You
Resources, study material and everything in between -
Deep Learning Specialization I learned deep learning from here, after completing the 4th Course, I decided to start this project.
PyTorch Crash Couse - By Sentdex. I learned Pytorch from here. Really awesome playlist with to the point explanation.
MobileNet with Pytorch I used official documentations as a reference for transfer learning.
Chandrika Deb's Mask Detector It is a similar project, so whenever I was lost, I used this as a reference. Also the Readme of this project is heavily inspired by her's
PS-I recently learned deep learning, so there may be a better approch to this project. Any kind of improvement or suggestions are most welcomed.