Giter VIP home page Giter VIP logo

face-mask-detection's Introduction

Face-Mask-Detection

In order to protect ourselves from the COVID-19 Pandemic, almost every one of us tend to wear a face mask. It becomes increasingly necessary to check if the people in the crowd wear face masks in most public gatherings such as Malls, Theatres, Parks. The development of an AI solution to detect if the person is wearing a face mask and allow their entry would be of great help to the society. In this, a simple Face Mask detection system is built using the Deep Learning technique called as Convolutional Neural Networks (CNN). This CNN Model is built using the TensorFlow framework and the OpenCV library which is highly used for real-time applications. This model can also be used to develop a full-fledged software to scan every person before they can enter the public gathering. Using this model, an accuracy of over 96% is obtained. This can also be used further to achieve even higher levels of accuracy.

Medium Article - Click Here!

Data -

I have used the face mask dataset provided by Prajna Bhandary available at Github

CNN Architecture -

In this proposed method, the Face Mask detection model is built using the Sequential API of the keras library. This allows us to create the new layers for our model step by step. The various layers used for our CNN model is described below.

The first layer is the Conv2D layer with 100 filters and the filter size or the kernel size of 3X3. In this first step, the activation function used is the ‘ReLu’. This ReLu function stands for Rectified Linear Unit which will output the input directly if is positive, otherwise, it will output zero. The input size is also initialized as 150X150X3 for all the images to be trained and tested using this model

In the second layer, the MaxPooling2D is used with the pool size of 2X2.

The next layer is again a Conv2D layer with another 100 filters of the same filter size 3X3 and the activation function used is the ‘ReLu’. This Conv2D layer is followed by a MaxPooling3=2D layer with pool size 2X2.

In the next step, we use the Flatten() layer to flatten all the layers into a single 1D layer.

After the Flatten layer, we use the Dropout (0.5) layer to prevent the model from overfitting.

Finally, towards the end, we use the Dense layer with 50 units and the activation function as ‘ReLu’.

The last layer of our model will be another Dense Layer, with only two units and the activation function used will be the ‘Softmax’ function. The softmax function outputs a vector which will represent the probability distributions of each of the input units. Here, two input units are used. The softmax function will output a vector with two probability distribution values.

alt text

After building the model, we compile the model and define the loss function and optimizer function. In this model, we use the ‘Adam’ Optimizer and the ‘Binary Cross Entropy’ as the Loss function for training purpose.

For the face detection, the Haar Feature-based Cascade Classifiers are used in this experiment. It is is a machine learning object detection algorithm used to identify objects in an image or video and based on the concept of features proposed by Paul Viola and Michael Jones. In this, a cascade function is trained from a lot of positive and negative images. It is then used to detect objects in other images.

The cascade classifier used for this experiment is the Face Detection Cascade Classifier. In this, a model is pre-trained with frontal facial features is developed and used in this experiment to detect the faces in real-time.

Finally, the CNN model along with the cascade classifier is trained for 30 epochs with two classes, one denoting the class of images with the face masks and the other without face masks.

Demo -

face-mask-detection's People

Contributors

gurucharan-marthi avatar

Stargazers

 avatar Parth Vashista avatar Tiffany-maker avatar  avatar JaySon avatar  avatar Mahmoud Alabsi avatar  avatar Letter_ avatar Kerem Erkinsoy avatar  avatar Jarvis_MAX avatar wenyuan avatar  avatar Shan avatar  avatar  avatar AliceLIKER avatar Amin Affandi avatar persible avatar Simran Shilky avatar Rio Julian Azis P avatar  avatar liangzelang avatar Christopher Christian Cosingan avatar  avatar  avatar PuHsin avatar Ajin Frank J avatar Ghiwook Nam avatar OMKAR NAVNATH WAGHMARE avatar evea avatar  avatar Chaitanya Kanagala avatar ranhaoliu avatar Saurabh Kumar Verma avatar  avatar zaid kamil avatar 白鹭先生 avatar xyxu avatar  avatar Dan Ellis avatar  avatar BalaShankar avatar  avatar MY avatar I Gede Adi Martha avatar Rajarshi Ghoshal avatar  avatar  avatar Satyam Chourasiya avatar SEGU VENKATA AKHIL avatar Ufuk Bombar avatar Jack Douglas avatar Abrar Hassan avatar Deepak Purti avatar  avatar gizemdagdeviren avatar Daniel Jadi avatar Azat avatar  avatar Rupanshu avatar ArthurKun avatar Rijul singh malik avatar DIPMAN avatar Mohd Abdul Azeem avatar Ishan Khandelwal avatar Abdul Ahad avatar Tamer avatar Eueung Mulyana avatar Ahmet Gökdayı avatar semiventurero avatar Avni Onur Pehlivan avatar Okan DAVUT avatar  avatar erkan balaban avatar  avatar Ömrüm Baki Temiz avatar  avatar Hüseyin Mert avatar HAKAN BAYIR avatar Unai avatar Saleh Ahmed Rony avatar Arpitha Ananth avatar  avatar Ahmad Rifa'i avatar Ayşen Özün Türkçetin avatar Prafulla Raichurkar avatar Utkarsh Sharma avatar  avatar Monika Suresh avatar  avatar  avatar Japesh Methuku avatar Michael R. Bernstein avatar M. Khairul Makirin avatar  avatar Ravikiran Dhulipala avatar tomo avatar

Watchers

erkan balaban avatar Rajarshi Ghoshal avatar Ravikiran Dhulipala avatar Jilol Kiols avatar  avatar

face-mask-detection's Issues

Uploading Dataset

How you had uploaded dataset? Or how can I upload dataset on google colab?

face mask detection perameter

what would be the perameter of this fun
def split_data(SOURCE, TRAINING, TESTING, SPLIT_SIZE):
dataset = []

for unitData in os.listdir(SOURCE):
    data = SOURCE + unitData
    if(os.path.getsize(data) > 0):
        dataset.append(unitData)
    else:
        print('Skipped ' + unitData)
        print('Invalid file i.e zero size')

train_set_length = int(len(dataset) * SPLIT_SIZE)
test_set_length = int(len(dataset) - train_set_length)
shuffled_set = random.sample(dataset, len(dataset))
train_set = dataset[0:train_set_length]
test_set = dataset[-test_set_length:]
   
for unitData in train_set:
    temp_train_set = SOURCE + unitData
    final_train_set = TRAINING + unitData
    copyfile(temp_train_set, final_train_set)

for unitData in test_set:
    temp_test_set = SOURCE + unitData
    final_test_set = TESTING + unitData
    copyfile(temp_test_set, final_test_set)

YES_SOURCE_DIR = "dest_folder/val/yes/"
TRAINING_YES_DIR = "dest_folder/train/yes/"
TESTING_YES_DIR = "dest_folder/test/yes/"
NO_SOURCE_DIR = "dest_folder/val/no/"
TRAINING_NO_DIR = "dest_folder/val/no/"
TESTING_NO_DIR = "dest_folder/test/no/"
split_size = .8
split_data(YES_SOURCE_DIR, TRAINING_YES_DIR, TESTING_YES_DIR, split_size)
split_data(NO_SOURCE_DIR, TRAINING_NO_DIR, TESTING_NO_DIR, split_size)
location of dataset

It cann't identify when I already wear a mask.

Hi Gurucharan
I have a question when I detect facemask.
It only show red rectangle “without_mask” when i don't wear a mask.
It cann't identify when I already wear a mask.
I hope you can give me assistance.
Thank you.

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.