Face Mask Detection using Convolutional Neural Networks - Python | Keras | Tensorflow | OpenCV
Вставка
- Опубліковано 11 вер 2024
- This tutorial explains a method of building a Face Mask Detector using Convolutional Neural Networks (CNN) Python, Keras, Tensorflow and OpenCV. With further improvements these types of models could be integrated with CCTV or other types cameras to detect and identify people without masks. With the prevailing worldwide situation due to COVID-19 pandemic, these types of systems would be very supportive for many kind of institutions around the world. Please let me know your ideas, suggestions and concerns in the comment section and feel free to improve this project yourself and come up with better results.
Download the code (Github): github.com/aie...
Download the code and Materials (Google Drive): drive.google.c...
Speaker: Thakshila Dasun
Could you make a full tutorial with explaining everything from the scratch what are the requirements to do this properly.
Sure I will soon.
@@aiwiththakshila6656 sir when i am waiting for it
@@aiwiththakshila6656 sir can you make full tutorial as mention above please!!
@@aiwiththakshila6656 When will you do a tutorial ?
@@aiwiththakshila6656 pls hurry up brother. I am waiting for this
best lecture for this project
1. The "haarcascade_frontalface" model is failing to detect faces with mask.
2. Even for image without mask the model is detecting mask and shows "MASK"
please help.
I got the similar issue.
I gave the author some credit to walkthrough the CNN process ( load training data, how to ingest the training data , and how to predict the result) , however, the program in python is not working as desired
1) The training model is not stable and different result from re-run. It seems that model_016.model file provides the best accuracy. However, If you run the training script multiple times, you do not always get to 016, sometimes, I got model_009.model.
2) It shows "mask" 99% times for a person without mask.
3) The face detection is not working well for the model haarcascade_frontalface, sometimes, it marks a face for window curtain and ceiling fans.
Anyone getting constant errors on OpenCV while running the face detection file?? Please help!!
subcribed! im gonna be waiting for more tutorials related to deep learning with live object recognition
very good lecture. I am happy to find such kind of tutorials. please make more lectures. I am realy happy to find the link. very informative lecture. thanks sir. please upload more lectures.
Hi, thanks you for the code, it works well, sure it is written no mask without mask, but the problem is that with mask it isn't written anything. what should I do.
Can you plz send code harishdasari963@gmail.com
yeah i had this problem too
same issue
Hi,
I tried running your code. The model is only detecting NO MASK. When I wear a mask, it's not detecting. Can you please help with probable reasons?
you can use this one, github.com/rupakdas18/Face-Mask-Detection-using-Traditional-CNN
hi,
i don't know how to run the code and not to connect my webcam.please help me
@@venkatreddy-nv2hc What software are you using to run the code?
@@rupakkumardas2351 jupyter sir
@@venkatreddy-nv2hc Try to use spyder
Hey guys whoever is facing the accuracy issue just change the pixels to 224 and then accuracy and val accuracy boosts up to 90 percent
in which line exactly? please help
Wonderful Tutorial bro, you earned my respect+++ , Your life long subscriber .
Thank you for your best explanation,,it is very very useful for me and it's 100%working.
Hello sir' great explanation but there is problem because, it cannot detect face after applying mask and I this problem is because I don't have object classifier.ipynb file
Pls solve this problem
Your doing a great job buddy 👍, thanks for sharing your knowledge. keep up the good work 👏👏
Thank you for your best explanation,,it is very very useful for me and it's 100%working.thank you once again ...🙏🏻🙏🏻
Can you guide me sir, if I want to write the same code in vizual studio then how can I do it?
Bro u are a master your method to reach the target its a mix to easy effective end your explanation its very clear
Thank you 😊
@@aiwiththakshila6656 are u on discord
This model is detecting good when the face mask is not there but it is not detecting the face itself when the face is masked . I think haar cascade classifer is trained on faces without mask . So I think the masked face is not identifing . Correct me if iam wrong.
Thanks for the video
I am also getting exactly same issue. Please comment back if you can find the solution
Actually i just modified the aim of the project to detect only faces without masks and that means it only detects the people who violets the safety norms and this model fits fine for detecting the people without masks
any solution?
the project is working fine but it does not respond to the masked face as it is only giving result for no face mask. What is the problem ??
same issu
plz tell some solution
@@saudaminimohapatra4329 same issue did u find any solution?
I tried to implement the same but my accuracy is not increasing its around 0.5.. only
why is it?
how to solve this problem?
Did u make any changes?
@@aiwiththakshila6656 none. we are getting validation accuracy around 47%. Can you rerun and verify your model's performance?
hey try increasing the ROI or the pixels 100 100 (Mostly wont work) u can push it to max 50 in validation
I think none will work as the training samples are less so we need more training samples
What is correlation between haar cascade and CNN?
I'm new in machine learning, can anybody explain me which cnn model used in this video ??
Good video sir need many more like this
dhinesh kumar I made algorithm for same but I need feedback can you please watch and give it ?
ua-cam.com/video/JtexyRC6e1Y/v-deo.html
sir, I do not have much space to download images. Can you please tell me how can I use image url
thanks sir...providing such clear content on face mask detection on webcam
Bro I tried a lot to fix the error but I couldn't solve the error
so please help me to solve the error
in training file it's showing that input_shape is an unexpected keyword argument
very good lecture please make this video again lie by line code and briefly at the begging of the juypter installation up to last running of the code i think you have get a lot view and subscribers i miss you
Instead of using a haarcascade use a model trained with many data using keras it can give more accuracy.
@13:57 shouldn't it be gray[x:x+w,y:y+h] ?!!!
This video was random to me
Now I'm subscribed thinking that i get practical knowledge on ML
Only webcam required right??
what changes are needed to run it on google colab??
Have u found out the solution?
@@abhijithbinoy875 no I didn't get solution
Hi, I'm a newbie to machine learning, I would like to know if we try to implement this on a video captured from a CCTV camera, should the dataset be changed or does the CNN still give a accurate prediction ?
Here's a paid course for this and it's worth paying.
khadymschool.thinkific.com/courses/data-science-hands-on-covid-19-face-mask-detection-cnn-open-cv
Sir , did face mask detector also detect the scarf or handkerchief use to cover our face ???
Hello sir i getting this error how to solve it
ImportError: cannot import name 'np_utils' from 'keras.utils' (C:\Anacond3\Lib\site-packages\keras\utils\__init__.py)
Great work. Aiya..
Hey sir nice work but why we r using keras nd one more doubt its like u have saved the modules of video but if we want to test it live like when we execute and run the code at that time webcam open show so that there is no need to save the models .......nd yes then how what changes i have to do.Can we implement without neural network.
Sir please how can be detect the face and maskes , i download the datasets and i run your program ,it not detect the the face and mask , please help me
I have used cascade classifier to detect the face. When the mask is on, some of the features in the face are not visible, therefore sometimes the face is not detected when the mask is on. If you try with a better camera and better light conditions (day light), it may work well.
bro iam facing
ModuleNotFoundError: No module named 'google' this error when i try to compile keras.utils to import np_utils. kindly help me in this bro.
It is not able to detect with mask. Please tell me where it might be going wrong.
Is this better compared to transfer learning (like mobileNet) so there is no need to use a cascade classifier?
Sir, I tried to run your code and it is not detecting persons with mask
error: OpenCV(4.6.0) C:\b\abs_f8n1j3l9l0\croot\opencv-suite_1691622637237\work\modules\highgui\src\window.cpp:1267: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage' , i am getting the error like this what should i do know
It is showing only NO mask when i'm not wearing mask but showing nothing when I wear the mask
Were you able to solve this issue?
I'm getting the same problem.
@@vatsalchandra781 Not able to solve but I tried sitting with bdifferent backgrounds and it worked at some.
Thank you very much for this easy tutorial.
Supperb work. Please create biginner level tutorials series.. Good luck 👍🏾
Sure! thanx for the motivation
While training the model, it is only considering 31 images instead of 990. Can you suggest me something how can I proceed?
While debugging the all data is loading perfectly and it is also getting divided correctly into train data and test data. Does anyone also faced the same issue?
@Akshay Kagwade,I am also facing the same.In the video here,all 990 images are taken but when i tried it only 31 images were taken.
@AI with Thakshila,can you please help me fix this?✌✌✌
@@nithyashreev3404 I am having the same issue it is because haar cascade can only detect patterns of black and white and it seems the project works fine only if simple plain mask is worn.
same issue here
I have a problem in 3.0 detecting masks in the last cell, which I can't fix, please help me.
error: OpenCV(4.5.4-dev) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
Will this work if I don't use the ROI and just use the camera feed. I can move my face close to the camera. I've read that lighting conditions make the face cascade better but I'm not sure exactly how to do that.
Muy buen video pana, saludos de Colombia.
I have a problem in the last part, im using colaboratory: penCV(4.6.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
The program doesn't show mask when you have mask on. I think there's a problem with the dataset or the loop.
Same here! Did you solve it?
@@aukerulmoin4311 for me the model is performing poorly. try building the model with a pretrained model like Mobilenet. The model itself isn't identifying the face with mask on.
For me the validation accuracy is 47% instead of 97% accuracy shown here.
@@SoumendraBagh I'm trying to import mobilenet, but getting some error. Can you give me source code please?
@@aukerulmoin4311 haven't worked on it till now. Will get back to you once done.
@@SoumendraBagh Okay. Thanks in advance
i want to count the number of people with and without masks and show the result on dashboard using flask.. do you have any idea how it can be done?
can anyone help me i am trying to run the last notebook and it does not open a window for my webcam what might be the issue everything else runs fine
Cascade classifier file is not available in the github code sir.. Please share
Great work..! Thank you Sir..!
It does not detect correctly when I run. I have no mask and it says mask. Is it an expected inaccuracy or do you think some technical error occurred?
You can change your dictionaries, probably your labels were assigned inverted.
I changed the model and it worked
Please sir, if I use three records in my dataset: "with mask", "incorrect worn mask" and "without mask". What changes should I make in this case? You have not shown us how to do this if we are using several folders.
I made this change: model.add (Dense (3, activation = 'softmax')). The model training is going well but I get an error at the end that says: Shapes (None, 1) and (None, 3) are incompatible.
And when I launch the program, it's only the face with NO MASK that are recognized.
Bro do you finish it
Why coverting into gray scale image ?
May I know how to upload this dataset folder to google colab
How to do over fitting and under fitting in computer vision
InternalError: cudaGetDevice() failed. Status: cudaGetErrorString symbol not found.
I have installed CUDA 10.0 . I have checked my environment variable path too. How do I solve this error?
Thank you.
hi can i use that code for more than 2 class to detect the use of mask?
after doing everything the camera is not opening ,the camera will be running but it wont open and show live as u shown above
why did you convert it into 4d array in the beginning ???
Best explanation sir
There is an error coming while doing the VideoCapture part of openCV. Can you please help.
Which cnn architecture has been used?
Why is that you have takes categorical cross entropy
As there are only 2
Why can't we take binary cross entropy can't we take in that manner!?
Cascade classifier is not detecting any face when mask is on. I have tried with daylight also. no region of interest is created.
please help.
Me too,even after the model download ed from Google drive
you must have good camera quality.
I tried with a good quality video and it works
hi am an problem in keras "jupyter notebook's kernel keeps dying" can you help me?
What is the detection algorithm used in the training the model?
all the dataset contains only white colored mask i had used black mask but it did't showed the label mask with green color. It shows correct when i am without mask. But with mask it did't show anything.
Hi! great video! Is it possible to add an other model, for example with glases? I mean, un the dataset folder add to the mask and no mask folder one with glases.
Great video sir 😍😍😍😍
Best video about this
i used your model but it is overfitting but after using data augmentation it is underfitting
Hey ,how can you do data augmentation ,can you send your project code.. my mail :bhaumikchaudhari225@gmail.com. Please help me .
I tried installing keras but it shows module not found, could you please explain
try using tensorflow.keras instead of keras
How did you save the cnn model in your local machine?
Sir apke jo IN[15] me error ara h konse packages install krne h plz reply asap
Sir how to upload the dataset in Jupyter notebook
?
module 'keras.optimizers' has no attribute 'TFOptimizer' it is giving this error >> how do i remove it please help
Could you please create video for training the model in cloud free GPUs including the deployment also?
Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation.
please help me.
Great work... will try to follow the implementation.. keep it up 👍
Sure, Chathura, Thanx for the motivational words!
Can I do this as my final year project? Please reply
Can I know where exactly the output with mask and without mask is stored in video progran
perrmission to learn sir.thank you
The last line is not running in short the webcam is not opening and the last line is just processing only but not running
Error when checking target: expected dense_2 to have shape (2,) but got array with shape (1,) sir im getting this error when i try to fit the model
Use this after train_test_split() :
from keras.utils import to_categorical
train_target = to_categorical(train_target)
Which algorithm is used for this please tell me sir
Does this produce a trigger if a person is not wearing a face mask?
if we cover the face with hands what it will show mask or no mask??
Hey I run your code but I'm getting error as
NameError Traceback (most recent call last)
in
1 while(True):
2
----> 3 ret,img=source.read()
4 gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
5 faces=face_clsfr.detectMultiScale(gray,1.3,5)
NameError: name 'source' is not defined
what should I do?
Thanks for the video and well explained.
Thing is i am seeing green rectangle with txt "MASK" whenever i face the camera and don't see any result from the model when i wore mask. seems like my model is only able to predict class "MASK" but unable to predict other class "with Mask"
I am facing a similar problem. I think the issue is that haarcascade classifier is not very able to recognizes faces with a mask on. Maybe you should try another means of face detection.
same with me
@@pavankumark2450 yes same thing is happening with me.
Thanks for the video, it show around 95 percent accuracy but while testing the system doesnt detect my face with a mask. is it a problem with haarcascade?
Same problem here, did you find out a solution?
Sir I have doubt that how many frame detect from video in 1 second?
How can I get an alarm when there's no mask triggered?
Coding Kahan py milygi ye Jo ap ki h?
sir how did you extracted/downloaded "model-017.model" file ?...
in my case 19th epoch gives least validation loss value and best accuracy , so i need to use "model-019.model" file, but from where to get that file?
save your model using model.save('yourmodelname')
can it detect cloth masks or only surgical masks?