Git Product home page Git Product logo

face-mask-detection-pytorch's Introduction

Face Mask Detection using PyTorch

A simple Face Mask Detection Model created using PyTorch and OpenCV.

πŸ“ƒ Installation

  1. Clone the repo
$ git clone https://github.com/rakshit087/facemaskDetectorPytorch.git
  1. 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

πŸ”ΉThe faceExtractor can be used to extract face images from pictures. This is what I used to improve my dataset. Put your Images in the 'Images' folder and all the Extracted faces will saved in the 'saved' folder after running the app.py

$cd /YOUR_PATH/facemaskDetectorPytorch/Face_Extractor 
$python app.py

πŸ”ΉYou can train your own model, but for that first you need your own dataset. The dataset must have the following structure-

.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

πŸ”Ή You can use a pretrained model with the help of 'faceDetect.py', by default it will load the model I trained.

$cd /YOUR_PATH/facemaskDetectorPytorch/Use_Model 
$python faceDetect.py

πŸ“ Dataset Used

I created a custom dataset by mixing images from various sources.
πŸ”ΉCabani's Dataset - I used it to get images of people wearing mask
πŸ”ΉReal vs Fake Face - I used it to get images of people not wearing a mask.
πŸ”ΉI also some some personal images of my friends and family and extracted faces with the help of 'Face_Extractor'


🧠 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

πŸ”Ή The model is having a hard time to detect dark masks, I tried to improve it by adding some dark mask images but somhow, the model started giving false positive to by beard face. πŸ˜›


πŸ’œ 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.

face-mask-detection-pytorch's People

Contributors

rakshit087 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

face-mask-detection-pytorch's Issues

requirements.txt is incomplete

i ran requirements.txt and after running

python app.py
It told me no module named tqdm

python faceDetect.py

ModuleNotFoundError: No module named 'torch'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.