safety jacket and safety helmet detection | raspberry pi tensorflow-lite custom object detection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome to YouTube channel Freedom Tech and in this session what we are going to learn in this session we are going to DET take construction site worker safety means we are going to detect a helmet and we are going to detect safety jacket with the help of tensor FL light using Raspberry Pi 4 latest Raspberry Pi OS book War 64bit version using simple USB web camera so before we move to our practical friends if you learn something from our videos please consider to subscribe our Channel okay friends thank you so much and let's get started so friends as I mentioned today we are going to detect construction site workers safety helmet and their safety jacket with the help of tensor Flite and we are going to use here our Raspberry Pi 4 and we are going to use latest Raspberry Pi OS book War 64bit version and for that we are going to use here our normal USB web camera so let's get started for that I have create a repository I will mention the link inside description box you need to Simply copy paste the link inside the browser as you can see and this is the repository rpy book war helmet sefty jacket detect TF light webcam just go to the code click on download zip and it will download our ZIP format repository as you can see we download our repository minimize browser file manager go to the downloads this is what our repositor right click extract here it will extract our repository as a folder right click cut go to the home and then just paste here our repository so now go inside our repository so this is completely fresh installation of latest Raspberry Pi book War 64-bit version for that first we want to run some command commands so open RPI 4. txt file right click open with text editor it will open our rp4 text editor file as you can see so First Command sudu RM USR Li python 3.11 this is just a command just copy the command copy it open Terminal and just paste that command inside our terminal and then just it enter that's it so now we are going to install our packages so we need open CV hyphen python then we need here uh media pipe package for tensor flow light so simply open the terminal again and sudu sudu pip 3 install sudo pip 3 install open CV hyen python this is what our first package sudu space pip3 space install space open CV hyen python just hit enter it will install open CV on our latest Raspberry Pi book forarm 64bit version as you can see the process is started so it will install open CV meanwhile I will pause video so friends we have done with open CV package now we want to install media pipe package so sudu space pip 3 space install media media pipe sud P space install space media pipe just H enter it will install media pipe on our book War 64bit version and as you can see process is started so it will take some time so friends as you can see we install our media pipe package also now let's just clear our screen and now we are going to install label IMG so just go inside our repository so our repository is basically sl/ RP book forarm helmet safety jacket detect your flight webcam M so simply run here CD command or let's just first run LS command so this is what our repository as you can see this is what our repository so run CD space RPI high1 and press tab button it will autoc complete our repository name and then just enter now we are inside our repository let me make full screen terminal so if I run here LS command here it is uh we have here label IMG Dosh bash script which install label IMG so CH mode space 775 and mention the script name which is label IMG Dosh first we want to mention the full permission so CH mode space 775 space our script name our bash script name which is label IMG Dosh just hit enter now if you run LS command as you can see the color is green it means we change the permission now simply run the command bash space our script name which is label IMG Dosh just hit enter now it will install label IMG on our latest raspberry pios bookor so friends as you can see we install label IMG now let's just clear the screen and if I run CD command because just come out from the repository and if you now run the command label and just press St button it will autoc complete IMG so label just type label press tab button it will autocomplete our label IMG command and then hit enter and as you can see we open our label IMG software means we successfully install label IMG on our book form now we have done with package installation we have our label mg so for custom object detection model of course we want to create our own data so for data purpose we are going to use our USB web camera normal USB web camera and we are going to collect our data so for that let's just minimize our terminal open repository for that inside our repository I have create IMG dopy so just open with Tony python ID imgp right click and open with Tony python ID so here first we want to switch to regular mode so click on switch to regular mode click on okay and now just close our Tony python ID now we switch as a regular mode for Tony python ID now again right click to the imgp code and open with Tony python ID that's it now here it is as you can see CV2 do video capture 0 0 is basically our index number USB web camera so we are going to capture here 70 images for each class so basically we are going to create here three classes one is helmet another one is no helmet and another one is safety jacket so this is three classes which we are going to create for our custom object detection model so first first class let's just say helmet so mention here helmet as you can see I have mentioned here helmet and then we want to create our folder so open our repository and inside that repository Cate create a folder which is image image this is our folder and right click to the image folder copy the path and from images just remove it remove the path because we create a new folder and just press contrl + V it will copy paste our path of our images folder which we just copy open repository create H create a new folder then right click to the folder copy as a path mention the name image and then simply paste here C2 do imite just remove from image and then just press crl plus v it will copy paste our new folder path that's it and then mention the name the class of name helmet that's it now it will capture 70 images of helmet with. jpg extension and it will save all the images inside our image folder so so now what I will do I will start the code and when I will start the code it will start my USB web camera some simply I will wear the helmet on my head and then I will move in front of the ca camera so this is what my images for helmet class and then simply I will remove the helmet and I will create a no helmet class images of course with 70 the 70 number the frames is basically 70 and then I will wear my safety jacket and I will create a safety jacket of 70 images simple so let's just start with helmet so now I will start the cord and I will wear the helmet and I will move in front of the camera that's it so friends as you can see I have create helmet data so if you open our repository inside that we create our images folder and inside that we have our helmet images so if you right click and image viewer open with image viewer as you can see we have here our images which we capture using our USB web camera so this is for helmet class now same way just mention here no helmet no hyphen helmet save the code now this time I will not wear helmet okay so friends we create no helmet images so if you open again file manager and our repository and inside that we have our image folder and now we scroll down and now we have as you can see we have now no helmet images so just open it as you can see this is what helmet images and this is what no helmet images simple 70 so now simply our last class which is safety jacket safety jacket so just change the name remove the no helmet and mention safety hyphen jacket and just save the code now I will start the camera and it will capture the images with safety jacket simple [Music] for so friends as you can see we collect our safety jacket data again simply open file manager our repository image folder and now if you scroll down and scroll down scroll down and at the end as you can see we have now new images which is safety jacket 70 images if you open with image VI as you can see we have safety jacket images simple we have no helmet images and we have helmet images so this is how friends we can use our normal USB web camera for collecting our own data for our own custom object detection model simple now simply we are going to open our data with the help of our label IMG software so friends now simply open terminal and run the command label l a press stab button it will auto complete our Command hit enter it will open our label IMG software simple as you can see we open our label IMG software so minimize terminal and close the Tony python ID and make it full screen label IMG software go to the open DI go to the our repository rpy bwarm helmet because inside that we have our image folder click on choose and now as you can see we select our images change save di same way RP book form our repository again select image folder our image folder click on choose that's it now here we want to select Pascal vo then click on create rectangle box and now simply draw a rectangle box on our object means on the helmet and mention the class which is helmet click on okay Save It Go for next image create rectangle box draw rectangle box on the helmet then click on okay Save It Go for next image create rectangle box draw rectangle box click on okay save it so this is how we want to draw a rectangle box on each image for helmet images simple so now I have already draw a rectangle box on the images that's it so I already done with label IMG process so I will show you how I have draw the rectangle box on helmet also for no helmet also for safety jacket simple so friends as you can see this is what images folder which we create and as I mentioned I have already trained my images as you can see so image their XML file for helmet class and then we have here a no helmet class also as you can see we have here no helmet class their XML file and then we have safety jacket images and their XML file so now let me open label IMG software label IMG open DI and repository images folder click on shoes as you can see this is for helmet class so if I go back or let just go for next image so as you can see I have trained a helmet class like this way simply we want to draw rectangle on helmet choosing Pascal vo so this is for helmet class 70 images helmet class and as you can see this is for no helmet class so here as you can see there is no helmet so we want to simply draw a rectangle on on the person head so this is for no helmet because here there is no helmet so simply draw a rectangle like this way so this is for no helmet class as you can see no helmet and if I go for next image and as you can see now simply this is for a safty jacket here it is as you can see there is a safty jacket and simply we want to draw a rectangle box like this way just on the safety jacket simple as you can see safety jacket safety jacket so this is how this is how you want to draw a rectangle box with the help of label IMG software on each class simple so friends now if you open our repository and inside that repository we create images folder and inside that images folder we have our data uh so just open images folder and as you can see we have here our image and their XML file image and their XML file simple so we have done with our label IMG process now simply create a new folder inside our repository so right click new folder and mention the name freedom take so freedom take this is what a folder so create a new folder mention the name Freedom Tech and now go inside a folder which we just create Freedom Tech and inside that folder again create two new folder first one is train and next one is validate so right click new folder train this is what our first folder then again right click new folder validate simple so create a new folder inside our repository name Freedom Tech and go inside a freedom Tech folder again create two new folder first one is train and next one is validate done now simply go back and go inside images folder where we have our all the data so just press crl + a select all the data then right click copy and paste all the data inside Freedom Tech Train folder just paste it simple go back same way inside validate folder just paste the data which we copy it from our images folder so this is how you need to copy and paste all the data from images to Freedom Tech Train folder from images to Freedom Tech validate folder done now we want to create a freedom Tech folder as freedom tech. zip file because we want to upload our freedom tech. zip file on our Google Drive so simply for that again open RP 4. txt text file and inside that text file I have mentioned the command for creating a zip format file this is the command as you can see this is the command so just open Terminal and run the command CD space and our repository name so first let's just run LS and our repositor name is as you can see RPI bookor so so CD space RPI bwarm just mention a name and just press tap button it will autocomplete full name of our repository just PR just mention CD space RP high1 press t button it will autocomplete the repository name and then just hit enter now we are inside our repository if I run the command LS as you can see we have here our freedom Tech folder so now simply open our text file copy the second command which is for creating zip format file so just open Terminal and just paste the command and then just hit enter as you can see it will create our freedom Tech folder as Freedom tech. zip file inside our repository so it's creating so we have done so if you open folder as you can see we have now Freedom tech. zip file so simply now we are going to upload this file on our Google Drive so let's just open your Google Drive so I have opened my Google Drive go to the new click on file upload and then go inside our repository rpy book form helmet safety and then we have our freedom tech. zip click on open so now as you can see it's uploading our freedom tech. zip on our Google Drive so meanwhile simply we are going to upload our uh tensorflow light training file on our Google collab so open Google collab go to the upload browse and just go inside our repository so home and this is what our repository inside that I have mention our Google collap file for tensor flight custom object detection model so just select it click on open now it will upload our collap file on our Google collab so friends as you can see we upload our collap file on our Google collab so simply go inside runtime change runtime type then select Python 3 select T4 GPU click on Save then simply click on connect now it's connecting so friends as you can see we have successfully connected now simply we are going to run our cell one by one so let's just start with first celles just click on play button it will create a virtual environment so we have done with first cell now simply run a second cell click on play button and it will start our second cell so friends as you can see for second cell for proceeding second cell as you can see it says yes or no so simply select it and then press y from the keyboard and just hit enter now it will process simple so friends we have done with our second cell so just go for next cell click on play button done now again next cell it will create my environment with python 3.9 version on Google collab so here also we want to mention yes or no it will ask a permission so if you scroll down as you can see proceed yes or no so simply we want to proceed so just press y from keyboard and then hit enter it will start our process done now simply we want to install tfight hyen model maker package so just click on play button it will install tfight hyphen model maker p uh package so friends we have done with tfight model maker package installation process just scroll down scroll down and now we are going to install uh ipy kernel package as you can see so just click on next cell play button and and it will install ipy kernel package so we have done with ipy kernel package now simply again scroll down scroll down now we are going to install open CV hyphen python package so just click on play button and it will install open CV hyphen python so done with open CV hyen python so for next sale just click on play button and it will install numai version 1.234 package done just scroll down now next cell it will install Pi Coco tools as you can see PB install Pi Coco tools then just scroll down and now we want to mount our Google drive because we need our freedom Tech doz file on our Google collab so for that we want to upload not basically upload we want to mount our Google Drive on our Google collab so let's just uh go on the Google Drive and we have done with our uploading process as you can see we successfully upload Freedom tech. zip file on our Google Drive so now simply we can mount our Google Drive so let's just run our sale click on play button so we want to mention a permission so connect to Google Drive select your Gmail ID as you can see this is what my Gmail ID so select it then click on continue scroll down then click on allow now it will Mount our Google Drive on our Google collap so friends we successfully Mount our Google Drive on our Google collap Now simply we want to unzip our freedom tech. zip file so click on play button it will unzip our freedom Tech .zip file as you can see we have all the data done now friends we want to upload our train.py on our Google collab so just open the repository and here it is we have our trend. PI so first let's just mention some changes inside trend. piy then we are going to upload our trend. piy on our Google collab so right click to trend. piy open with Tony python ID as you can see we open our train. PI and here here it is as you can see Freedom Tech SL train Freedom Tech / train so here we want to mention our classes so helmet safety jacket and let me mention here because this classes which I have already mentioned so helmet and then we have no helmet class helmet then no helmet and because we have three classes helmet no helmet and safety jacket so safety hyphen jacket this is what our last class helmet no helmet safety jacket so this is for Trend folder and then we have validate folder so same way helmet then we have our next class which is no helmet no helmet and then we have last class which is safety jacket safety hyphen jacket helmet no helmet safety jacket for Trend folder helmet no helmet safety jacket for validate folder done now just scroll down and we are going to use here 100 apox done just save it and now open our Google collab just click on this folder button and then here as you can see just click on upload so this is just a sign or we can say log go click on that button and it will open our uh local file manager so just go home and then go inside our repository and we have our train.py file just click on open and then just click on okay and it will upload our trend. PI as you can see we have successfully upload our trend. piy on our collap file done now just scroll down we are ready and this is what our last sell which create our own custom object detection model which detect helmet no helmet and safety jacket three classes so just play the button click on the play button it will start our process so friends as you can see is started our aox 1 out of 100 so it will take some time meanwhile I will pause video so friends as you can see we have completed our training process now if you click here and then uh as you can see there is a best. TI flight this is what our custom object detection model for tensor FL light so simply click on here and then click on download now it will download our model best. TF light so friends as you can see we download our model so now simply minimize browser and we want to go inside home folder then downloads and inside downloads as you can see we have our best.to flat right click cut go home folder and go inside our repository rpy bookor hel helmet and here simply paste our model B.T flight now simply we want to open our detect. piy with the help of Tony python ID so right click to the detect. piy open with Tony python ID and and as you can see we open our detect. PI and here if you scroll down here it is as you can see I have mentioned the webcam index number which is zero because I have here only one USB web camera so index number is zero and if you scroll down you scroll down here and at the line 132 at the line 132 as you can see the default model is basically our pre-trained object detection model for tensor light so right now we are we are not going to use our pre-trend model so we are going to use our own custom object detection model which we create which is best. TF flight so I have simply mentioned here line 133 default is equal to b. TF flight now it will automatic detect object with the help of our own custom object detection model so now we are ready and now we are going to cross check our model we are going to uh we have here our own helmet we have here our safety jacket so simply we can check our model so let's just start so if I start the code it will start USB web camera simple and then we are going to cross check our model for so friends as you can see it's detected no helmet also it's detected our helmet now I'm going to Simply wear a safety jacket simple so friends as you can see we create our own custom object detection model for tensor flight on Raspberry Pi 4 which detect our helmet and safety jacket I hope you will learn something from this video we'll meet our next video till then thank you take care and bye-bye
Info
Channel: FREEDOM TECH
Views: 2,539
Rating: undefined out of 5
Keywords:
Id: Gmq_IvVkuwM
Channel Id: undefined
Length: 35min 14sec (2114 seconds)
Published: Mon Jan 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.