Build a Face Mask Detector in 20 Minutes with Watson and Python
Vložit
- čas přidán 26. 07. 2024
- We’re living in strange times at the moment.
And it seems like wearing masks in public are becoming the norm.
So…maybe you’d like to detect who’s wearing one and possibly who’s not.
This is a perfect problem for deep learning and object detection.
In this video you’ll learn how to use Watson Visual Recognition, Python and OpenCV to build a face mask detector. By the end you’ll have all the code required to deploy your very own face mask detector with Python. In this video you’re detecting face masks but you could also use this to detect a whole bunch of other objects as well!
In this video you’ll learn how to:
1. Capturing Images with OpenCV
2. Visualising detections using Matplotlib
3. Training Custom Object Detection Models with Watson
Github Repo for the Project: github.com/nicknochnack/FaceM...
Want to learn more about it all:
OpenCV: opencv.org/
Watson Studio: cloud.ibm.com/catalog/service...
Watson Visual Recognition: cloud.ibm.com/catalog/service...
Oh, and don't forget to connect with me!
LinkedIn: / nicholasr. .
Facebook: / nickrenotte
GitHub: github.com/nicknochnack
Happy coding!
Nick
P.s. Let me know how you go and drop a comment if you need a hand!
Music by Lakey Inspired
Chill Day - • LAKEY INSPIRED - Chill... - Věda a technologie
High Quality content man !! you deserve 1million subs i m sure u r gonna get more than that !! kudos to ur hardwork👍
Oh man, thanks so much @Sumedh Dixit! Appreciate it a million!
Bro, It was Awesome...... I madly love what you have done. Expecting more videos on OpenCV in future. All the very best bro.
Thank you so much @venkata sreeram, definitely, plenty more to come👨💻!
Loving these videos Nicholas!
🤟🤟🤟 hell yeah, thanks @Ken!! Just checked out your channel mad ❤️!!
Super video amazing clarity and frankness
Thanks so much!
Amazing work man thanks for sharing the knowledge
Anytime!! Thanks so much for tuning in!
Great video, Thanks!
🙏🙏🙏 Thanks so much @Sukant!
You are awsome man!
Brilliant!
Way to go. Best of luck
Thank you so much @Shafaq Malik 🙏
Keep Going Nicholas... Best of Luck 👍
I'm on it 👨💻, thanks so much @46.Akangsha Mukherjee!
Love your content, can you please make a full tutorial on React-Js and React Native from start to Finish? :)
Definitely @Viraj Shah, I’ll add it to the list!
As usual, fantastic !!!!!!
Legend! Thanks so much @Varun
I really like your content. Best of luck 🤗
Heya @Sendanur, 🙏🙏🙏 thanks so much, plenty more to come!
Bro,make a video on a guideline or roadmap on how someone become a data scientist. Hope u will take it into consideration. Btw,it was a great video.
Awesome suggestion @Mohammad, I'll put it on the list of non-technical videos I've got coming!
I've been trying to fix my recognition model in watson but every time I train the model then test it out, the detection scores are way off and the boxes appear in the wrong place. I've tried the method you used to capture images with python and I've also tried image sets of people with and without masks from online but the results are still the same, any advice?
Definitely! So there's a few things you can do here:
1. Upload and train your model with more images
2. Use images with a bigger variety, different angles, different lighting, different people
3. Increase your confidence score when predicting, so that you only show the results with the highest likelihood of a result
thank you for this great work
Thanks so much @Radhwen!
THAT WAS AMAZING!
THANK YOU SO MUCH,
I really needed to watch this video for my graduation project!
Keep it up 👍🏻😍
AWESOME! Glad it was useful @Yara!
Impressive work! Unfortunately I am only getting version v3 in the lite plan, so I cannot do the last part of the tutorial. Also, I saw that IBM will shut off the server for visual recognition in Dec. 21...
Heya @Jonas, I believe that's still the case 😞 (it wasn't when I released the video unfortunately). I've started putting together an open source set of CV tutorials to help out the YT fam, a little more involved but you get wayyyyy more control: czcams.com/play/PLgNJO2hghbmhUeJuv7PyVYgzhlgt2TcSr.html
hi sir my web camera isn't opening for me to record the images with mask and without, I am using pycharm and this the error which I get- " [ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\videoio\src\cap_msmf.cpp (434) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback" please help me out
Hey!!!
how did you start capturing the images @ 5:10
didnt understand that
Heya @pahal, it's done with OpenCV. It'll immediately open up an image capture window that you can use to capture images!
Please make more difficult projects with functionalis like, without mask person 's count, take pictures of them, alarm system etc
Great vid, btw you write really fast and without mistakes lol.
Hahaha, I speed up the coding in the vids, I also make a sh*t ton of mistakes. I think this was one of my early YT vids where I wanted it to look perfect.
Hey @
Nicholas Renotte open cv imshow Error in windows how to solve this
OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-memyuvq3\opencv\modules\highgui\src\window.cpp:651: 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'
Hello sir!! great video
I am getting an error when running in colab in the line
cv2.imshow('frame', frame)
please help :(
Heya @Mudit, what's the error?
Heyy, silly question here....do you require an external webcam for this?
No silly questions my man! The video uses an integrated MacBook webcam. If you didn’t have an integrated webcam then yep, you would need an external camera. Let me know if you need a hand 🙂
I am trying to access to set up the visual recognition service, and it seems like they don't have the Lite plan?
Heya @Ruiyu Qu, I think this might have changed recently. I'm putting up a new tutorial soon on building from scratch!
Hello Sir, I am having a problem with my Watson studio, when I choose to create my own image detector the page freezes. So is there any other alternative to Watson studio?
All good! Let's dig into it:
1. Can you try clearing your cache and cookies
2. Do you have a visual recognition service up and associated to Watson Studio
3. The other alternative is to do it via the API but that doesn't have a GUI cloud.ibm.com/docs/visual-recognition?topic=visual-recognition-object-detection-overview
@@NicholasRenotte Well, I figured out that I didn't have a visual recognition service up and associated to Watson Studio. Thanks a lot!!
Nice explane
is the watson studio model training necessary?
Unable to label image on watson studio. Kindly help. Getting this error
Error in Watson Visual Recognition service: Received empty image data respons
Heya @Bilal, is there a larger error?
Hey Nicholas, I am constantly getting an error like:
An error occurred while updating 0a4ec073-7151-11eb-88fa-841bf56a51fc.jpg
Error in Watson Visual Recognition service: Received empty image data response.
This error comes whenever I try to label object for an image Mask or NoMask. Any solutions ??
Heya @Ujjwal, looks like the image might not have been passed through successfully. Try comparing to the baseline code!
heyy i am in my code it's coming cv2 not defines 'cap' not defined
what to do bro
Try running the cell that creates the video capture. Should be something like this cap = cv2.VideoCapture(0)
Gold content!
Thanks so much @Jonathan!
is IBM Visual Recognition deprecated? I can't find though
Yeah it was @Thirasha, check out the Python alternative instead: czcams.com/play/PLgNJO2hghbmhUeJuv7PyVYgzhlgt2TcSr.html
Bro how we can add voice alert along with this system??
Yep @Nivethitha! I'll make a note for the real time video, once a detection occurs it can trigger an email alert or play a sound!
Hey Nicholas, I am getting this error
OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
the same, how u solved this problem?
(-215:Assertion failed) !_img.empty() in function 'cv::imwrite i have this error, please helpme!
Heya @Marcelo, just double checking you're running this on a local machine and you have access to the webcam?
Very nice thing! But im getting this error!
File "", line 7
if cv2.waitKey(1) & 0xFF == ord('q')
^
SyntaxError: invalid syntax
Can you try running without the & 0xFF == ord('q') @Brandhan Dey?
🔥🔥🔥
Thanks big @Bronson Ranga!!
hey Nicholas, my code is showing
NameError
in
NameError :
name 'cap' is not defined.
Hmmm, have you definited the opencv capture?
We have seen the content of checking the mask on your Youtubu channel. Can you provide an API that can be used in the unity program? We are going to do a project to check whether to wear a mask. I look forward to your response.
Hey definitely, check this out: github.com/watson-developer-cloud/unity-sdk
I am trying really hard...not finding a solution to my error mentioned below pls help me out
No problemo! Check out the code that needs to be added in the other comment 🙂
Whether visual recognition model is available now in Watson studio?
Nope, unfortunately deprecated.
hi nicholas how can ı convert this notebook file to a real py project with GUİ
Heya, check this out: czcams.com/video/IOI0o3Cxv9Q/video.html in that vid, we build a real time model and create a GUI using the OpenCV imshow functionality.
where do i have to create this Images folder?
Should be in the same directory as the notebook!
why when me press q, my frame have error ?
can i ask what algorithm is being use here? thank you for answering !
Heya @Anime, I believe this is using a ResNet architecture!
great video, it helped me a lot, thanks.
Is it possible to use that model in real time?
Heya @antonio guilherme tebas, not this one but I'm making a video on real time face mask detection this coming week!
More than a week later but it's out: czcams.com/video/IOI0o3Cxv9Q/video.html @antonio guilherme tebas!
@@NicholasRenotte great!!!! many thanks bro. another great tutorial!!!
@@antonioguilhermetebas241 thanks so much!!
I get
No module named 'ibm_watson'
When I try to run
"from ibm_watson import VisualRecognitionV4
"
at point 2 Scoring
Heya man, can you try running the following command in a cell:
!pip install ibm-watson
pip install --upgrade ibm-watson
I forgot to do this! My fault
@@arthurarturo4625 happens to the best of us! Let me know how you go!!
Please help used his image writer, not working(
Double check you have the full file path created, might have a subfolder missing!
You need to pay to use Watson Studio?
In associate a service. Visual recognition is missing.
Heya @Arkham unfortunately the service has been deprecated. Try checking this out as an alternative: czcams.com/video/IOI0o3Cxv9Q/video.html
why am i not able to use different images captured it throws error saying coollection error?
Not too sure, would need to see the error to help debug. Can you try this notebook, it's an updated version of the image collection code: github.com/nicknochnack/TFODCourse/blob/main/1.%20Image%20Collection.ipynb
@@NicholasRenotte thanks will try this out!
@@TaniaVelu awesome, let me know how you go!
What is the meaning of Watson Studio as a training model
Heya @Aryaman Chatterjee, Watson Studio is the data science platform. You can do a ton of DS and ML stuff from there.
Hey Nick, here it was where I got stuck:
----> 4 cv2.imwrite(imgname, frame)
error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
.
Please NOTE: I am running all of this in Colab, hope that should not be any issue?
Heya Aman! With Colab, you need to do a little more work to access your webcam. Check out this solution under Camera Capture: colab.research.google.com/notebooks/snippets/advanced_outputs.ipynb#scrollTo=2viqYx97hPMi
@@NicholasRenotte I am getting the same error even though i am working in a Jupyter notebook.
The error is as follows:
----> 4 cv2.imwrite(imgname, frame)
error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:738: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
@@achendvankar hey ac did you solve it
I am also getting same error did anyone solved it?
IBM Watson™ Visual Recognition is discontinued. Existing instances are supported until 1 December 2021, but as of 7 January 2021, you can't create instances. Any instance that exists on 1 December 2021 will be deleted.
Yah, a bit of a pain but I'm going heaps of open source vids on OD.
This is gold! How do i make it a real time detection?
Heya @Zaheer, can't do it with this model, but you can with this: czcams.com/video/IOI0o3Cxv9Q/video.html
@@NicholasRenotte yes I've already came across it while going through your channel 😁😁😁
@@zaheersuhabuth2677 awesomeee!
I'm getting this error......... when I type this code
authenticator = IAMAuthenticator(apikey)
service = VisualRecognitionV4('2018-03-19', authenticator=authenticator)
service.set_service_url(url)
AN ERROR SHOWS UP saying:
name 'IAMAuthenticator' is not defined
please help..
Hey there! Can you add this before your authenticator code.
# Install IBM Watson
!pip install ibm-watson
# Import authenticator
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
@@NicholasRenotte Thanks a lot sir, it means a lot to me!!!
hi, i have a question. when you take a photo with a mask, without a mask in a notebook, do you yourself press to take a picture, or does the code itself take pictures several times?
Hey Nicholas! I couldn't figure out Visual Recognition thing in Watson Studio.
In Watson Studio :-
Step 1 : Add Project
Step 2: Select Visual Recognition
Step 3: To provision.... click here thing
Step 4: I couldn't find / see in my UI the Visual Recognition service option
Please help me out figure how to proceed on adding Visual Studio service (associate)
Thanks already man!!
Heya, it's been deprecated unfortunately. It isn't available anymore, I've got some open-source examples using TFOD on the channel though!
Hey there Nicholas! Great video. Can you help me locate the Images folder. I have searched in the env folder(anaconda3) as well as the notebook directory. I found nothing but the IPYNB files inside the directory. :)
Heya @Sid, have you created an image folder for collection?
Heyy@@NicholasRenotte :), Yes I did, but then I couldn't find any images inside the folder("Images/Mask"). All I could find were the IPYNB files(notepad) and the IPYNB checkpoints. (:
Hey there@@NicholasRenotte, I got this working after creating a new directory(from scratch). Thank you (: peace. (='w'=)
@@sid5072 awesome work! HMU anytime!
Where are default folder jupyter notebook?
Normally wherever you start your jupyter notebook server from!
Sir please make video tutorial face recognition with mask identification
it identify person even he/she had a face mask
OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
i am getting this error whenever i am executing third line and also i am getting many traceback errors like assertion failed, can you provide me a solution for it
how to get rid of it
Use 0 instead of 2 in cap
In Watson Studio, whenever I try to label any image it gives me an error message saying "Received Empty image data response" .. Can u plz help to solve this...
You're API is up and running? I believe the service is deprecated for new instances.
@@NicholasRenotte I tried using the visual recognition service by creating a new account but it won't let me... Is there any other way to complete the object detection step but still continue with your tutorial??
@@koustavroy8703 not with this one unfortunately if you can't create the API. Are you down for giving it a try with open source?
@@NicholasRenotte yes plz... would love to👍👍
Hello Sir, hope you are doing fine. All my codes are working fine, but is there a way to get Real Time mask detection?!
because I am not able to access it. Please help me out as usual.
Hi @Vrishab Vishnu, this tutorial is focused on non-real time detection. I've got a real time tutorial coming up!
@@NicholasRenotte okay great!! Can't wait for it then!!
Heya @anonymous three, it's finally out, an end-to-end walkthrough on building this model for real-time: czcams.com/video/IOI0o3Cxv9Q/video.html!
Thank you for this vidio i have an error with cv2.imwrite(imgname, frame)
error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
same with me. did you get any solution?
Heya @amal and @Deep Patel, this is normally because your webcam isn't capturing any images. I'd suggest the following:
1. Ensure that your webcam is on and activating
2. If it is and still not capturing, restart your Python Kernel
3. Ensure that the file name and file path are correctly defined
@@NicholasRenotte thanks for the reply . While I was doing this project my camera drivers got uninstalled 😂 and it’s not getting back now even if I restart . Any leads.?
@@deeppatel195 try restarting your kernel, stop Jupyter and kick off everything again?
maybe 3:14 issue
Can you please send your source code sir?
HOW MUCH TIME DOES IT TAKE TO TRAIN MODEL
SAME AS 44 IMAGES AS YOU
Heya @Aditya, I don't rememember the exact time unfortunately but it didn't take that long.
Hey Nicholas, can you help me deploy this in a real time live camera.
Definitely!! I can do one better for you @Himanshu, here’s how to do it in real time with opencv: czcams.com/video/IOI0o3Cxv9Q/video.html and this is how to do it with JavaScript: czcams.com/video/ZTSRZt04JkY/video.html
@@NicholasRenotte Thank You Nicholas, I checked out these videos, it was very helpful for me, but I have a idea to add in it, and its to add one more label i.e. incorrect way of wearing mask, I am trying to do it following the your steps, thank you again!
@@himanshu00712 great question, during your labelling step you can add in another class (e.g. called incorrectly worn) and train with it to add it in.
It is not working for unmasked image!
Hmm, might need a little performance tuning!
Thanks for the video, can you please elaborate next time? I'm looking forward to it as my graduation project, and i am not really familiar with these websites, shortcuts 😅
What did u use to insert extra line 11:50
Also what did you do/press to insert camera images into jupyter. I'll need to keep seperate folders ready for the same?
Also please can i get in touch with you somehow for doubts whenever youre free? 😅
Take a look at this @Nikhil, I go into way more detail: czcams.com/video/yqkISICHH-U/video.html
Can I get IEEE research paper for this particular project
Heya @Kruthika Rajesh, not quite IEEE but it's based on Yolo, here's a paper describing it: openaccess.thecvf.com/content_cvpr_2016/papers/Redmon_You_Only_Look_CVPR_2016_paper.pdf
I have a code that reads the photo or video and determines if a mask is wearing or not. The question is how to calculate the accuracy
Heya @Sherif Eletriby, want to share your code and I can take a look?
It throws out an error and I can't seem to find an answer to it:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in
----> 1 obj = analyze_images['images'][0]['objects']['collections'][0]['objects'][0]['object']
2 coords = analyze_images['images'][0]['objects']['collections'][0]['objects'][0]['location']
KeyError: 'collections'
Hey 👋 @Farhaan Ashraf, what do you get if you print(coords)?
And now my IBM lite account is deactivated or something... so is there any alternative for Watson Studio?
How u took pictures at 5:10
Try using this code :) github.com/nicknochnack/TFODCourse/blob/main/1.%20Image%20Collection.ipynb
Can I make face detection website using python?
Sure can, would need to use something like Django or Flask @Rahul!
Can I copy whole code of python.. and website degine by react.. is it possible..
@@RahulSharma-zy3lg could have a Python API and a react front end yep!
can this be done in real time?
Sure can!
@@NicholasRenotte idk how to thank you but, your projects help students in many ways , cant thank you enough!! Thank you for being a good teacher and always making good content🏅♥️
Why am I cannot associated with a Watson Visual Recognition service?
Heya @Peter, I believe it's been deprecated unfortunately. This is the updated open-source version: czcams.com/video/IOI0o3Cxv9Q/video.html
@@NicholasRenotte much appreciate it! Already watched the video.
@@peteryang3228 awesome! How did you go?
My frame is not responding anyone please help me
Yup, hmu in your other comment so it's in one spot :)
Please implement through real life scen
With a real time camera for example @Ashoka?
By switching on camera
@@ashokabalaji definitely, check this out: czcams.com/video/IOI0o3Cxv9Q/video.html
Hello sir...firstly thank you for the wonderful project.....since I m doing ur same project as my mini project....as I m doing it I m getting a Name error for the cap variable.....can I get a help frm u as soon as possible 😊
Ya definitely, try changing the number in cv2.VideoCapture until you see your webcam activating!
@@NicholasRenotte sir do I need to install opencv and numpy in my system?
@@Ramya_BAIS yep!
@@NicholasRenotte but I m doing it on Google collab
@@Ramya_BAIS oh, you that won't work for the image collection as you need to be able to access your webcam. Once you've collected your images locally you should be able to run the detection on Colab if needed!
Hello Nick, I have some trouble in compiling this, could you help me please 🥺
My frame is not responding
Anyone please help
What part is freezing? The collection or rendering?
@@vishnubhotlabharadwaj2070 me too
What if you cover your face using your clothes?
Hmmm, try testing it out. I'm guessing you wouldn't get too many detections back.
Wow
Glad you liked it!
Watson visual recognition is discontinued you cant create new instances any more
Same :*) Just when I start :(
@@anirudhank6337am really exhausted
Ya, bit of a pain. Can do it with open source though!
@@NicholasRenotte could you please explain this in detail....like is there any way to it else where is there any common name to stuff like this?
@@NicholasRenotte please send the link