raspberry pi tensorflow lite custom object detection | raspberry pi tensorflow lite custom model

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 see how we can create our own custom object detection model for tensor flow light on Raspberry Pi 4 rasbian OS Bullseye 64bit version but 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 create our own custom object detection model for tensorflow light on rasbian bull size 64-bit version for that simply first go here in menu programming Tony we want to install let us open CV on our rasb bull 64-bit version simply go to the tools manage packages and search for open CV hyen python just hit enter it will search open CV hyphen python package click on it and and I already installed that's why it says uninstall you need to Simply click on install button and then it will install open CV hyphen python latest on our Raspberry Pi for raspberry 64 version that's it now simply close all these things and for tensorflow light I have create a repository I will mention the link you need to Simply copy paste the link inside the browser then go to the code and click on download zip it will download our ZIP format repository so as you can see we download our repository now simply minimize the browser go to the file manager and then we want to go inside our downloads folder so downloads and this is what our repository as you can see tensor light custom model so right click and click on extract here it will extract the folder so simply right click the folder cut and move the folder in our home directory so so as you can see I have move my folder in home directory so simply go inside the folder so first we want to install a tensorflow light so tensorflow light. s this is the B script so open Terminal if I run LS command here and we have our repository as you can see this is what our repository General light custom model main so CD tensor light custom model hyphen Main run LS command and this is what our bash script so we want to give the full permission so CH mode 775 CH mode 775 as you can see CH mode space 775 then again space and mention the file name The Bash file name which is tensorflow so just write te press tab button it will automatic complete our B script name just hit enter now if you run the ls command as you can see the uh file is basically in green color it means we successfully changed the permission now simply we want to run our bash file so bash and our file name uh bash script name basically tens light hyon uh s hit enter and now it will download example folder and inside that example folder we have our setup.sh file which basically install 10 Sur light on our Rasin Bo say 64bit version so first it will download our example folder as you can see it's cloning the example folder so friends as you can see we done so if I run LS command and here it is whatever examples folder examples so now simply open the file manager and inside our repository transfer light custom model main this is what our repository inside that we have our example folder simply click on it then go inside light folder then again we have examples folder and then here we want to search for object detection folder so here it is as you can see we have object detection folder then go inside Raspberry Pi folder and here we have requirements.txt file so right click and open with the text editor and here we want to change the open CV version so by default open CV version is 4.5 so we want to mention here our latest version which is 4.8.0 so just change the version open CV hyperon like this way 4.8.0 simple and click on file and just save it that's it we successfully mentioned the changes now just close the file manager and now we want to change our path from our terminal also so because we want to install our setup.sh so right now if I run the command PWD so we are inside slom SLP and this is what our repository so first we want to go inside our example folder so if I run LS command here it is as you can see we have examples folder so run the command like this way CD space space examples folder then we have light folder then we have again examples folder then we have object detection folder then we have Raspberry Pi folder so this is the folders which we want to go inside so first we want to mention the CD command space mention examples slash light/ example SL object detection folder and then Raspberry p folder and just hit enter now if you run PWD command so we are now inside all this folder and the main folder is basically Raspberry Pi folder so just clear the screen if I run LS command so here it is what as you can see we have our setup.sh file so this is the best script for installing TF light on our rasp we know as bull so run the command bash space setup.sh and just hit enter it will now install tensorflow light on our rasb buy 64bit version so let's just complete our bash script process then I will start video again so friends as you can see we have completed our setup.sh file process now what we want to do uh we want to install some packages so simply again open our repository which is tensor FL light custom model Main and inside that we have our install.txt a text file so open with text editor and we want to Simply copy paste all these three commands so just first copy it and just paste here and just hit enter it will install protuff dependency for T of light on rasbian Bullseye that's it now now the second command just copy it and just paste it inside the terminal just hit enter it will install TF light support so it's already installed because I have already done with all these steps then the last command so just copy it from the text file and just paste it inside the terminal just hit enter it will install TF light run time on our rasb buai 64-bit version so as you can see requirement is already satisfied that's it now we are ready and we want to first test our default code so for that simply close all these things open menu programming Tony it will open our ton python ID then go to the file click on open now we want to go inside our repository so home then tensor light custom model main then examples folder then light folder then again examples folder then here we want to search for object detection folder then Raspberry Pi folder and this is what our main code which is detect. piy just click on it click on okay and it will open detect. piy just close untitle file and if you scroll down so by default it will basically start your USB web camera so I have connect the USB web camera with the Raspberry Pi 4 you can use your Raspberry Pi 4 inbu camera also you need to Simply first connect the Raspberry Pi 4 camera module with the Raspberry Pi 4 if you don't know I have already created the video how to connect Raspberry Pi 4 camera module with the Raspberry Pi 4 but right now I have connect my USB web camera with the Raspberry Pi 4 so here what we want just scroll down and uh here it is as you can see the image is equal to C2 do flip so right now there is no to flip image so simply commment this code image is equal to C2 do flip that's it we have done now simply run our code it will start our USB web camera and it will start TF light object detection and as you can see friends it detected me as a person simple so it means our tensor flow light is perfectly working now we are ready we have done with our tensor FL light basic uh installation steps now we want to create our own custom object detection model for tensorflow light and as you can see it's little bit slow because right now I am recording on same raspberry pi4 also we started our object detection so that's why the process is little bit slow so now we are ready we want to create our own custom model so for that first we need a label EMG software so so again open our repository and inside that repository I have mentioned the label EMG txt file just click right text editor and inside that I have mentioned the commands as you can see the First Command just copy it open terminal clear the screen and now we don't want to go inside the Rasberry Pi folder so just run the CD command and come out from our uh tensorflow light folder so now here we want to Simply run our pq5 de Hy tools command so just copy it from LA mg. txt text file and just paste it hit enter it will automatic install our package done now next package so open file text file and sudo pip3 install label IMG copied the command just paste it hit enter that's it we have done successfully install label IMG now we are ready now we want to create our data set so for that we are going to use our USB web camera for creating the data set so inside our repository I have mentioned the imgp so let's just open imgp with the Tony python ID it will basically uh capture our data images with the help of our USB web camera so here it is as you can see we open our imgp inside our Tony python ID so window size is basically 640480 and the max frames as you can see Max frames you can simply increase the max frames uh right now I have mentioned here 30 images but you can mention 1,000 images you can mention 5,000 images so right now we are going to train only 30 images for each class we are going to train here two classes one is basically Raspberry Pi and another one is basically ardino Uno board we are going to create a tensor light custom object detection model which basically detect our Raspberry Pi 4 also the uh ardino Uno board simple so here first we want to create the folder where we want to save our images so inside our same repository here I'm going to create a new folder which is images click on okay and now we want to Simply mention the path so just right click copy as a path and here CV2 do imite it will basically write all our images so we want to mention here our path so from images just remove all these things and just press cr+ V it it will copy paste our new folder path where we want to save our images so now the a is basically the image name so now first we are going to start with raspberry pi4 so just mention here Raspberry Pi raspberry let's say raspberry hyphen Pi so this is what our first data set name we are going to first capture the Raspberry Pi 30 images with the help of our L us web camera and it will save inside our images folder so now what we want to do we want to Simply take our Raspberry Pi 4 model and we want to move our model in front of our USB web camera it means it will capture a different different angle images and it will save inside our images folder so now Simply Save the code and run the code so friends as you can see I move the Raspberry Pi 4 in different different angle so it means we capture a 30 images so if you open our repository and inside that we create our images folder so here it is as you can see it's captured 30 images and the name is Raspberry Pi because we we mention here our image name is Raspberry Pi and the extension is jpg so if you open the image image viewer here it is as you can see we capture a different different angle images 29 images for Raspberry Pi so now same way we are going to change only our object name so here now I'm going to mention ardino ardino High Uno ardino Uno board just save it now it will capture ardino Uno 30 images so friends as you can see we have done with Hardo also so if I open again our repository this is what our repository inside that we have images folder and now as you can see we have our ardino board images so if I open with image viewer here it is as you can see we have already no 30 images also we have Raspberry Pi for 30 images simple done now we want to open all these images with our label EMG software so just close all this thing minimize is the Tony python ID and just open Terminal and here we want to run the command let me clear the screen and label label IMG as you can see you need to Simply mention here L A just press tab button it will autocomplete the command just hit enter and it will open our label IMG software as you can see it's open our label IMG software now simply we want to open DI and we want to go inside our repository where we have our images folder images click on choose and as you can see this is what our images again change save Di and same folder which is transer for light custom images we want to save our XML file inside a same folder now here we want to select uh Pascal V Pascal VOC now we are ready create rectangle box and draw the rectangle box on our object so this is what our object which is a Uno mention ardino hyen Uno ardino hyen Uno click on okay save it next image create rectangle box draw rectangle box same name AR no no click on okay save it next image create rectangle box r no no select it click on okay save it so this is how you need to draw a rectangle box on each image so now let me draw a rectangle box on both ardino and Raspberry Pi 4 then I will start video again so friends as you can see we have done with ardino Uno board now simply we want to select our Raspberry Pi for board so create rectangle box again same way we want to draw a rectangle on our Raspberry Pi 4 and here we want to mention raspberry raspberry hyphen Pi raspberry hyphen Pi click on on Okay click on Save It Go for next image create rectangle box draw rectangle box and Raspberry Pi this is what our second class so ardino Hy Uno is basically our first class and Raspberry Pi is our second class click on Okay click on save it next image same way draw a rectangle box select raspberry piie and click on okay now way I will draw a rectangle box on all raspberry pip board images so friends as you can see we have done with our image training process we have successfully completed a drawing rectangle on each object so simply close the label EMG software and minimize the terminal and if I open our repository because inside that repository tensor FL custom model main we have our images folder and as you can see the Ardo their XML file the Raspberry Pi and their XML file so we we have done with uh label AMG process now we want to Simply create a freedom Tech folder because in in tfight Google collab file I have mentioned the freedom te folder so simply create a new folder which name is basically Freedom Tech Freedom Tech this is what our folder name and inside that we want to create a new folder two folder train and validate so right click new folder first one is basically train click on okay then again new folder and valid dat valid date simple click on okay so now we have done with creating our folder now simply go back and inside images we have all the images with label simply press cr+ a it will select all the images right click and copy the images go back and go inside Freedom Tech folder train folder just paste all the data paste it all the images with their labels same for invalidate just paste it done now we have done with copy paste all our data inside train and validate process done now simply open the terminal we want to create here a zip file we want to create a zip file of our folder so again see CD we want to go inside our repository which is tensorflow hyund light custom model main so CD space mention our repository name simply press tensor and just press tab it will autoc complete the folder name just hit enter now if you press here LS and we have our freedom Tech folder now open the repository and inside label IMG do text file text editor I have mentioned the command this is the command as you can see it will create our ZIP file so just cop copy the command copy it open Terminal and just run over here just run inside tens light custom model main because we have here our freedom Tech folder and it will create Freedom tech. zip file it will zip all the data which we have inside our freedom Tech folder so just hit enter as you can see it's basically create a zip file so if you open tens light we have here Freedom tech. zip file now we want to move our this file on our Google Drive so friends as you can see I have open my Google Drive and here right click and click on file upload and we want to upload our freedom tech. zip which is home then our repository which is tensor flight custom model Main and freedom. zip click on open now it will upload our file meanwhile I have open Google collab and here we want to click on simply upload so click on upload click on browse and we want to go inside our repository where we have our Google collab file for training our own custom object detection model for TF light so just click on open it will open our file in our Google collab so friends as you can see we have successfully open our file Google collab file in our Google collab machine so now because there is some problem with dependency right now on Google collab so we are going to create a virtual environment for over creating our own custom object detection model for tensor flow light simple so first we want to Simply go in runtime then change runtime type and Python 3 select for GPU click on save it now simply we want to click on connect it will connect with the GPU so friends as you can see we have successfully connected with our GPU now we are going to run our cell one by one so let's just run our first cell which basically create a a virtual environment we have done now next cell which basically install our cond so friends here it is as you can see on second cell where we are installing our cond here it says proceed simply we want to mention here y for yes so just press y button from keyboard and just hit enter so friends as you can see we have successfully run our second cell now we want to move on our next cell just click click on it and it will run our next cell we have done now simply cond create it will create a environment the name of our virtual environment is basically my EnV and the python version is basically 3.9 so just click on it so friends here in cond create and my environment python 3.9 here also we want to mention procceed simply mention why for yes and just read enter so friends done we have successfully run our cell now we want to move our next cell where we are going to install our tflight hyphen model maker package so simply run our next cell so friends we run our cell successfully now next cell same way just click on it and it will start the process so here also we have done just scroll down scroll down next cell just click on it we have done now just scroll down again Run next cell done next cell done now simply we want to import our Google drive because we have our data on our Google Drive so here click on it will asks you to sign so connect to Google Drive select your Google Drive means you want to select your Gmail ID where you save your data scroll down click on allow that's it we successfully allow to access our data on our Google collab so it will basically Mount our Google Drive and here it is as you can see we have our freedom tech. zip now we want to unzip our data so just click on next cell it will unzip over all images with their XML file as you can see ardino hyen Uno this is what our first class and Raspberry Pi raspberry hyphen Pi is basically our second class now we have our data ready now simply we want our train.py code means the python file which we have inside our repository so just click on this folder and here we we can simply upload our local file so just click on and then go inside home then this is what our repository and inside that we have as you can see train.py just click on it click on open and it will upload our file so warning just click on okay and as you can see we upload our train.py now simply just click on because we want to edit something it will open trend. piy over here as you can see we open our trend. PI and here in Trend data and in val data we want to mention our classes name so here it is as you can see I have mentioned esp8266 and PCO in Trend data and in valid data also esp8266 and Pico so here we want to Simply mention our own classes name so remember one thing the name here you want to mention same as which we train our images so raspberry hyphen Pi so this is what our second class and first class is basically ardino hyen unu so let's just mention as it is ardino hyen uno ardino hyen uno and the next class which is second class is basically our raspberry Rasberry hyphen pie raspberry it's not dble y it's double r y That's it raspberry hyphen pi and Ardo Ardo hyph Uno same here in valid data just remove it ESP 266 and ardino Hy Uno and then here we want to mention Rasberry Rasberry just a minute raspberry hyphen Pi that's it raspberry hyphen Pi know know this is what our class so this is how you need to mention your classes so right now we have here two classes so I have mentioned two classes over here ulo is first class and second class is basically Raspberry Pi that's it we have done now simply control + S press here here it is as you can see my cursor is basically inside mouse cursor is basically inside train. Pi here it is is blinking so here simply press crl + S close the file we have done now we are ready and we want to start our trend. PI so just click on our last shell and it will create our own custom model so uh here I have mentioned only 20 aox you can simply changes let me show you here one more thing I'm going to pause the train I have paused the training and let me open again trend. Pi so here in file let's just scroll down let me make like this way and then we are going to scroll our file train.py and just here in this line as you can see line model is equal to object detector create in this line here it is as you can see the aox I have mentioned 20 so we we can simply change so here right now let's just say 100 so it will create 100 aox simple so again just press cr+ s it will save and just close trend. pi and now just start our training this is what our last sale now it will create our own custom object detection model for tensor flow light the process is started and friends as you can see the apox 1 by 100 because we mentioned 100 apox so now it will create 100 APO and after that we have our own tensorflow light custom object detection model ready simple so meanwhile I will pause video so friends we have done with our training session and here it is as you can see we have our model ready which is best. TF light this is what our custom object detection model for tensor flow light which we create simple so now just click on here and click on download it will download our B.T light model so as you you can see it's now downloading and we successfully download our best. TF flight just go here click on show in folder and it will show our model inside download folder so we want to move our TF light model our custom object detection model inside our repository examples and Raspberry Pi folder so just cut it from here or you can simply copy paste so let's just copy paste copy it go to the home and we have our repository inside that we have our examples folder then we have light folder then we have again examples folder then here we want to search for object detection folder so object detection folder then Raspberry Pi and here we want to paste our model so just paste it that's it so now simply we want to again open our detect dopy with the help of our Tony python ID so just open Tony and this is what our IMG dop so just close it because now we have done with our .p so we want to open our detect. PI so click on file click on open and then it will our open our repository tens light custom model main go to the examples folder then light folder then examples again then here object detection folder where is our object detection [Music] folder here it is object detection Raspberry Pi and detect. Pi click on okay simp simp so simply scroll down just scroll down scroll down and here it is as you can see on line number 116 line number 116 this is the by default model as you can see this is the by default TF light model so we want to Simply copy paste this line copy copy it the line and just paste it here and make it is in line just make it is in line and this line which is our by default model just comment it hash and here we want to mention our custom model which is base. tfl so just remove this one and mention here best. tfight that's it now it will use our custom model base. TF light so for that we want to we want to comment our by default model so if you don't want to use your custom model again simply comment this line and just uncomment default model so now we want to use our custom model so just comment by default model and uncomment your custom model that's it save the code and now we are ready simply start our code it will start our USB web camera and friends as you can see see it started our camera so now if I show the Raspberry Pi 4 so as I mentioned it really slow because now I am recording but as you can see it's detecting our Raspberry Pi 4 and the accuracy is 0.98 Raspberry Pi and then if I show uh ardin board and as you can see Ard un board 95% accuracy 96 so we successfully create our own custom object detection model for TF light we detect our custom object which is Raspberry Pi and ardino Uno board so I hope you 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: 5,391
Rating: undefined out of 5
Keywords:
Id: ldvlAMcGWIk
Channel Id: undefined
Length: 35min 46sec (2146 seconds)
Published: Fri Oct 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.