custom object detection tensorflow lite raspberry pi bookworm | raspberry pi os bookworm tflite

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 configure tensor flow light most easy way on latest Raspberry Pi OS book Warm 64bit version 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 conf figure tensorflow light on latest Raspberry Pi OS book Warm 64-bit version also we are going to create our own custom model for tensorflow light we are going to use here USB web camera also the Raspberry Pi 4 camera module so let's get started for that I have create a new repository I will mention the link inside the description box you need to Simply copy paste the link inside the browser then go to the code as you can see the repository name is basically T of light custom object book War so this is the repository go the code and then click on download zip and it will download our ZIP format repository as you can see it's now downloading so we successfully download our repository now let's just minimize the browser open the file manager go to the downloads and this is what our ZIP format repository so let's just unzip our repository so right click click on extract here it will extract the repository with our folder name so right click cut and go to the home and just paste it the repository that's it we have done now first this is completely fresh installation of book War 64bit version completely fresh installation so first we need our open CV package so if you open here terminal and let me make a zoom in here so if you open the terminal and if you run the command sudu sudu space pip 3 space install open CV hyen python this is what our basic package for tensor FL light main package open CV hyphen python so if you hit enter on bookor latest uh book one Raspberry Pi OS you will see this kind of error simple so for that we need a command so just open repository and here I have mentioned the rpy 4. txt file a normal text file inside that I have mentioned the command so just right click to the file name text editor it will open our file with the help of text editor and this is this is the command just copy the command copy it open Terminal and clear the screen and just paste the command inside the terminal and just hit enter that's it now we have done now let's just close first text file which you open minimize the file manager and this is what our terminal now let me clear the screen now if you run the command sudu space pip3 space install space open CV hyphen python this is what our Command sudo space pip three space install space open CV hyphen Python and just hit enter now it will install open CV hyphen python means U it will basically run pip three command now we can use pip3 command for installing any package on latest Raspberry Pi book warm operating system a 64bit version so as you can see now it's installing our main package which is open CV Hy python so it will take some time meanwhile I will pause video so friends as you can see we have successfully installed opencv on our latest Raspberry Pi book War operating system 64bit version that's it now for tensorflow light on latest Raspberry Pi book War Python 3 3.11 if we want to use TF light we need a media pipe package because now the TF light modules which we want on Raspberry Pi is Now supported with media pipe so if we want to use a tensorflow light on latest Raspberry Pi book War operating system we want to install media pipe package which is the main package for T light now so simply same way sudu pip3 space install space media pipe sudu space pip3 space install space media pipe this is the command and just hit enter it will install media pipe package on our book W as you can see collecting media pipe so now is installing media pipe meanwhile I will pause video so friends we have done with media pipe installation as you can see is install all other dependencies requirement is already satisfied and all other packages so we have installed open CV hyphen python package with the help of sudo pip3 install open we haveen python this is the command and then we install media pipe package same command sudu space pip3 space install media pipe this is how we need to install open CV and media pipe on latest Raspberry Pi book War 64bit version we have done so now simply open repository and inside that repository I have mentioned default model for tensorflow light object detection as you can see this is the default model and then D.P is the code for USB web camera and detc 1. Pi is the code python code for Raspberry Pi for camera module so first let's just run detect. piy it will open USB web camera and then it will start object detection with the help of tensor FL light so first you need to connect your USB web camera with the Raspberry Pi 4 or Raspberry Pi five then then you need to connect Raspberry Pi camera module with the Raspberry Pi for any version so if you don't know how to connect the camera module with the Raspberry Pi I already created the video I will mention the link watch video and connect the camera module with the Raspberry Pi that's it done so let's just Open detect. PI so let's just first open our Tony python ID so go to the menu programming Tony it will open our to Tony python ID and then as I mentioned this is completely fresh installation of book one so now if I open Tony python ID here we want to select switch to regular mode so just click on switch to regular mode click on okay then just close the Tony python IDE and now this detect dopy as you can see just right click and open with Tony it will open our python code with the help of Tony python ID and as you can see done so so here it is if you scroll down here it is as you can see cap is equal to C2 do video capture and I have mentioned the zero for index number of my USB web camera so if you want to use our USB web camera we want to mention this code cap is equal to C2 video capture now let's just start our code and there is a error I know what is the error because I have already configured this code for custom object detection so I have mention here b. T of light model as you can see and right now there is no b. T of Light which is the custom model we have our default model so I need to Simply um just a minute here in model section where is the model section just a minute here here it is as you can see I mentioned the B.T of light model because the code which I have already test with the custom detection for that I have mentioned here B.T of light but right now there is no custom model so I need to mention here our default model which is this one this one so I need to Simply command this line and start with this l so you need to also do this changes because I have mentioned here the custom object detection model that's why there is the error as you can see the error is basically this one unable to open the file B.L now I have comment my custom model and I have uncommanded the default one which is this one and the model which is default which I have already mentioned inside our repository as you can see this one so now let's just save our changes if you run the code detect. piy and as you can see friends it detected me as a person so tensor FL light basic model is perfectly working on Raspberry Pi book War right now it little bit slow because same time I am recording as you can can see same time I'm recording that's why it's little bit slow but it's work perfectly on book War latest Bookworm OS 64bit version so we have done with basic model our pre- Trend model now this is the code for USB camera USB web camera now go to the file click on open and select the detect 1. pi and inside that detect 1. p as you can see I have mentioned from PI camera 2 import Pi camera 2 and this is the code this is the code for Raspberry Pi 4 camera module Raspberry Pi camera module so now detc 1. Pi will start our camera module Raspberry p camera module and it will start our tensorflow light object detection so here also I want to mention here it is also as you can see I have mentioned the custom model so here simply command the custom model line and UNC commmand this default model line this one the line 116 116 just save it now if you run detch 1. Pi it will start my camera module Raspberry Pi camera module and then we have our tensor flow light object detection and friends as you can see now it's working with camera module that's it done now as I mentioned with success F configure most easy way we successfully configure a 10 surle light for USB web camera so also for the Raspberry Pi camera module remember one thing on latest Raspberry Pi book War python 3.11 we need to install media pipe media pipe package for tensor FL light on book W python 3.11 here it is as you can see the python 3.12 version then we done with default model now we want to create our own custom object detection model for tensorflow light so for that we need our data so of course we are going to use our USB web camera also you can use your Raspberry Pi camera module for images purpose because we are going to collect our data using our camera live data so here inside repository I have mention two code the imgp and IMG 1. Pi so I if you open imgp with the Tony python ID this one so IMG dop basically start USB web camera and then it will capture the images the images which we want to train for our custom model and then same way IMG 1. Pi if you open IMG 1. Pi so this IMG 1. Pi same way open raspberry P4 camera module and then you can use the camera module for collecting the images with the help of live data done so now simply we are going to use here our camera module code and then we are going to collect our data so the data purpose we are going to use here Rd noo board and esp32 board this two two uh classes which we are going to train so we need these two object images so for that first inside our repository we want to create here a new folder which is images so right click new folder and images folder done images folder inside same repository then right click to the images folder copy as a path and we want to mention the path over here here it is as you can see co2. imite images just remove the path because this is the old path and here we want to mention our new path so just press cr+ V and then it will copy paste our new path which we copied which we copy it using the images folder we create a new folder images right click copy as a path and just mention over here so this is what our new path and inside that what is our image name so image name is basically ardino and the extension is jpg so ardino and jpg so it will save ardino do jpg images and how many images I mentioned the max frames 30 so 30 images of ardino Uno board so if you want to mention here 200 so it will now save the 200 or it will capture the 200 images and it will save name .jpg so. jpg 200 images now we only want 30 images so 30 images ard. jpg is the image name simple so now just save the code now what we want to do we want to Simply move our ardin no board in front of our camera module in different different angle slowly then it will capture the 30 image now simply let's just start our code and as you can see it's captured the 30 images so if you open images and inside that images folder as you can see we have 29 images of ardino board so if you right click image viewer and here it is as you can see the live images data which we capture with the help of our camera module as I mentioned you can simply use your USB web camera I have created the USB camera code also which is IMG dop but right now I'm going to use my camera module so I have just start IMG 1. Pi for camera module done now same way let me close all these things same way we are going to capture esp32 board images so as I mentioned now just change the name ardino with esp32 just save it and just move your esp32 board in front of the camera module done so again if you open file manager then this is what our Repository images folder and then as you can see we have now here esp32 board images also here it is as you can see this one is our esp32 board and then we have rboard so we have done with data now for training purpose we need label IMG software so just open our repository again this one repository our repository and inside that I have mentioned label IMG do txt file this is the text file inside that I have mentioned the commands for installing label IMG on book War so just right click open with the text editor label IMG txt file and this is our text file just copy the First Command copy it open Terminal and let me clear first all the commands and then just space the command from our label IMG txt file to terminal this is the first command just hit enter it will install pqy hund da tools on your book War 64-bit version so friends as you can see we have successfully install our first package now our main package which is label mg so just copy the second command as you can see sudu pip3 install label mg so just copy the command and just paste inside the terminal and then just hit enter it will install label IMG on our book War 64bit version then we have done with label IMG also now just close all these things and minimize the file manager now open the terminal clear the screen if you watch my old video where I have explained how to install YOLO in that video also I have explained how to install label IMG on bookor for python 3.11 so if you run here label LA and just press tab button it will autoc complete our label IMG command hit enter there is a error on python 3.11 for label IMG so as you can see we open our software now select the open DI and we want to go inside our repository because inside that repository we have images folder choose then change save di again same folder again images folder choose and now Pascal vo the format we need for tensor flow light Pascal VOC now if you click create rectangle box and if you move your cursor on the label IMG software the label IMG just close for that we want to mention some changes so just open file manager again and then go to the file system route then we want to go inside USR then lib just a minute here we want to go just back again just go USR then local not liap local so just open USR then go to the local and here we want to go inside Li folder then we have Python 3 .11 as you can see Python 3.11 and then this packages and here we want to search for this folder lips Li IBS lips so as you can see right now I'm inside /usr local lib Python 3.11 and this packages folder and inside this packages folder we have our lips folder so just open it and here we want to change this can canvas. Pi so inside our repository I have mentioned the canvas. pi so we want to simply delete the old canvas dop and we want to mention our new canvas. Pi so just open Terminal and just file click on new tab and just come to the first step and here we want to go inside this this packages lips folder so run the command like this way sudu sudu and RM RM space like this way let me show you here sudu space just press the space button RM again press space button then a hyphone and RF this is the command for deleting file so sud space RM hyph RF and we are going to delete this canvas. Pi so just right click to the canvas. pi copy as a path so we copy the path for this file and just press space here and then just paste the path which we have just copied from canvas. PI file like this way as you can see sudu space RM space hyphen RF and then the path of our canvas dop which we just copy like this way just right click to the canvas Pi copy as a path open Terminal and just paste it and then just hit enter done so we successfully remove our canvas. PI from lips now we want to move our canvas. PI file inside our lips folder this path so just open Terminal again and we open the new one tab so this one is new tab and here we want to go inside our repository so run the command like this CD space TF and press the tab button it will autocomplete our repository name as you can see TF light custom object book forarm hyphen main just hit enter LS and this is what our file which we want to move so sudu space MV this is the command for moving the file so sudu space MV and mention the file name which we want to move which is the canas . Pi simple sudo space MV space canvas. pi and where we want to move we want to move here inside this path / USR local Li python 3.11 dis packages lips so just copy the path from here copy it open the terminal and this is the command sudu space MV canvas. Pi again space and then just past the path which we copy and then just hit enter it will move our canvas. PI so now if you open lips as you can see now we have our canvas dop done so same way we want to change one more file which is inside label IMG folder as you can see this is the folder label IMG so just open label IMG and label IMG dop so first we want to delete the old label IMG dop and then we want to move our label mg. Pi which I have mentioned inside our repository this one as you can see label imgp so we want to move this file inside our label IMG folder but first we want to remove the old one so for that right click to the label imgp again same way copy as a path open Terminal and just move to the first Tab and just run the command same way sudu space RM hyph RF sudu space RM space hyphen RF for deleting the file and then just paste the path for our our label .p file and then hit enter now if you open label angg folder as you can see there is no label im. Pi because we remove it now the new tab and here we are inside our repository now same way sudu space sudu space MV space our file which we want to move which is label IMG do PI label IMG do PI just a minute label it's a capital I okay label I is capital label im. pi as you can see so space MV label I Capital mg. Pi now where we want to move we want to again copy the path so just copy the path here it is as you can see the path is/ USR local live python 3.11 this packages inside that we have label IMG folder and inside that we have label im. Pi so just copy the path and open ter Minal and this is the command sudu space MV space label m.p our file and just paste our path and then just hit enter done as you can see label mg. Pi is there now close all these things just minimize the terminal close all these things and minimize the Tony okay now close tab and run here CD command clear the screen and now if you run the level IMG command sudu or let me check here okay there is no need to run sudu just run the label LA Press tab button it will autoc complete label IMG command so label IMG and then just hit enter it will open our label IMG software and as you can see it's open this one like this way open DI select our repository because inside that repository we have our images folder selected choose change save di same way go to the repository select the images folder choose now here we want to select Pascal VOC create rectangle box now if you move your mouse for drawing the rectangle the software will not close it means we successfully solve the error for label IMG now simply draw the rectangle on our object like this way draw it now simply we want to mention the class name so this is our Ardo board so Areo Doo Uno aruno Uno click on okay save it go to the next image create rectangle box same way draw the rectangle box on our object same class which is orino uno click on okay now if you open the file manager let's just cross check images and inside that as you can see we have XML file it means our label IMG is perfectly working so just save it go for next image create rectangle box draw the rectangle box select the class name click on save so now let me draw a rectangle box on ardin Uno as soon as I completed this process I will start video again so friends done with ardoo board now this is what our esp32 board same way just click on create rectangle box and then we want to draw a rectangle box and now we want to mention our new class name which is esp32 just click on okay Save It Go for next image create rectangle box draw a rectangle box on esp3 to board select the class which is esp32 click on okay save it next image create rectangle box draw rectangle box esp32 click on okay save it now let me draw a rectangle box on esp32 board so friends as you can see we have done now this is what our last image now simply we want to close our label IMG software so just close the label mg software and now just open our Repository again and our repository and this is what of imag folder so just open our images folder and inside that as you can see we have image their XML file this is for ardino and esp32 image and their XML file done so now just again come to the repository so now we are inside our repository and here we want to create a new folder which is freedom take so right click new folder freedom take this is the name click on okay and then go inside the folder Freedom Tech and here again we want to create a two new folder which is train and validate so right click new folder train train folder click on okay train and new folder validate validate as you can see train and validate done so we create a freedom Tech folder and inside that folder we create two new folder train and validate now our images folder and we want copy all the data we need to copy all the data so just press control+ a cr+ a select all the things right click copy go to the back our freedom Tech folder train folder just paste it just copy paste the data from images to Freedom Tech Trend then go back validate just paste the data done so we need to copy paste our data from images folder all the data from images folder to Freedom Tech folder just a minute to Freedom Tech folder to train then to validate also then now we want to create here Freedom t. zip file so for that I have mentioned the command which is inside label im. txt so just open label im. txt with the help of text editor and this is the command this one so just copy the command open the terminal and go inside the repository so let's just clear the screen and CD space just press the space button from keyboard so command is like this where CD space and our repository name so just press TF press tab button it will autocomplete our repository and then hit enter now we are inside our repository if you run here LS command hit enter as you can see this is what our freedom Tech folder so just past the command which we copy from our label IMG txt file this one I have already shown you label im. txt inside that we have our Command this one command for creating the Z file done so just close it and open Terminal so as you can see I have mentioned the command so we are right now inside our repository because in that repository we create our freedom Tech folder and inside that we have our train and validate folder so now just hit enter as you can see now it's creating our ZIP file so if you open our repository and here it is this one Freedom tech. zip now we have done now simply we want to upload our freedom tech. zip on our Google Drive so friends as you can see I have open my Google Drive and here we want to upload our freedom tech. zip so just right click right click over here file upload and then go to the repository and freedom tech. zip as you can see Freedom tech. zip select it click on open now it will upload our freedom tech. zip on our Google drive as you can see uploading one item so meanwhile we are going to open our collab file so Google collab click on upload browse and then go to the repository home this is the repository and select the collab file as you can see this one t light custom model then click on open now it will upload our Google collap file on our Google collap so friends as you can see we have successfully upload our Google collap file here we want to go inside run time then change runtime type select Python 3 T4 GPU click on Save and then click on connect here it is click on connect now it will connect our collab file with Google collab so friends as you can see we have successfully connected now we want to Simply run a Cale one by one so first cell just select it it will create a virtual environment then next cell the second cell so friends as you can see we are running our second cell and meanwhile it ask permission so here it is as you can see proceed yes or no so simply here select it and mention y why and then just hit enter now it will start a further process so friends we have done with second cell so next cell This One Imports this just select it and just click on play button it will run our next cell now this cell here it is as you can see cond create my environment with python 3.9 version so just run the cell so on this cell also it's ask a permission here it is as you can see on this cell where we have cond create an my environment python 3.9 on this cell here it is as you can see proceed yes or no so just select it and press y from keyboard and then just hit enter now it will go for next next process done next cell this one select it and just run it will install TF light model maker so friends we have done with Pip install TF flight model maker cell just scroll down and go for next cell This One PP install ipy kernel just click on the play button and and it will run this cell PP install ipy kernel so friends as you can see done just scroll down go for next cell PP install open CV hyph python python version so just click on play button so friends as you can see we have done with open CV hyphone python package now PP install nump 1.3.4 version so just select it the cell and it will install the packages done with numai go for next cell just click on play button done just scroll down now we want to mount our Google drive because we need our freedom tech. zip so if you open the Google Drive and let's just cross check our upload is completed we successfully upload our freedom tech. zip now just run this cell this is the code for mounting our Google Drive on Google collab so just click on play button then it will pop up this kind of window connect to Google Drive just click on connect to Google Drive we want to select our Gmail ID so this is my Gmail ID just select it as per yours then just scroll down and click on allow button just click on allow and now it will Mount our Google Drive on Google collab so friends as you can see we have successfully mounted our Google Drive now we want to unzip our freedom tech. zip here it is we have our freedom tech. zip we want to unzip the file so just select the next cell which is unzip our freedom tech. file and here it is as you can see we have our images which is Rin Uno and esp32 Uno done now select it the folder icon here it is as you can see this one selected the folder icon and we need to upload our trend. PI file so just selected this folder icon just click on this icon then and then go to the repository which is home and our repository name and inside that I have mentioned train.py as you can see train.py select it click on open it will open our train.py inside our Google collab here we want to Simply select okay and then as you can see we successfully upload our trend. PI just select it and click on the trend. pi it will open our file like this way here this is what our file and inside this file we want to make some changes so here ESP h26 and PCO this is what our classes which we want to train so here we want to mention our own classes so first class is basically add in Uno and the next one is esp32 so ardino just remove the old one first ardino Hy Uno IO Uno and the next one is esp32 here also in Freedom Tech validate folder same way just remove all one and mention like this way double quote r no r no hyphen Uno Aro hyphen Uno and the next class is esp32 so this is how we need to mention our classes which we want to train so this is for train folder and this is for validate folder so Ardo is basically first class and esp32 is basically next class the second class ardin Uno same way inside validate Ardo Uno and esp32 then just scroll down just scroll down and then friends here it is as you can see the line number 4040 we want to mention here aox so just make like this way here it is as you can see the aox is 20 we want to change the epox 20 with 100 so just select it and mention here 100 100 like this way as you can see I have changed 20 with 100 here it is let me show you here this is what bat size and epox epox is now 100 now we successfully change the aox by default it is 20 we need to mention 100 then simply press control+ s now we successfully save our file so if you close the trend. pi and if you again Open trend. PI for crosschecking and here it is as you can see we mention our changes which is Ard no no usp32 Ard no usp32 this is what our class names and here in line 40 so now as you can see the apox is 100 done now just close it trend. Pi now we are ready and simply this is what our last sell it will create our own custom model for tensorflow light so just click on the play button it will start our cell and friends as you can see there is some error uh in last cell there is some error and let me open train. Pi again we are going to solve the error what is the error basically let me check uh inside the trend. pi so I have open again trend. pi r Uno and R Uno oh there is typing mistake there is a type of mistake let me change r no no the class name which we mention there is a type of mistake ardino Uno that's it now perfect Ardo no esp32 esp32 let me press control+ s close trend. Pi now again we are going to try to run our last cell so just click click on it and now it will run now there is no error so it is basically a typing mistake a type of error the classes which we mention okay so that's why there is error now there is no error it will start our training so let's just wait because it will start our 100 Apo box and as you can see aox 1X 100 it means now there is no error and it will create our own custom model so it will take some time meanwhile I will pause video so friends as you can see our process is completed and we have our custom model ready best. tofight so just click here click on download and it will download our best. TF light model and friends as you can see we have download our custom model now minimize all these things and then we want to go inside file manager again and downloads because there is our model as you can see this is what our model which we just download right click cut go to the home and our repository this one tlight custom and then just paste the model over here paste it done so we successfully paste our model so again just open Tony python ID and close img1 dop now we are going to check our model both for USB web camera also for the camera module so start with detect. pi for USB web camera so here it is as you can see now again we want to comment our by default model line and then we want to uncomment our custom object detection model line so just comment the by default model line which is this one 132 and UNC commmand default best. T flag this is what our own custom object detection model and this is the detect. pi for USB web camera simple now we are ready Simply Save the code and if you run the code it will start our USB web camera so friends as you can see it started USB web camera and if you show the ardino board to the camera and as you can see it's detected ardino Uno board it's detected ardino Uno 0.95% it's Orin un board and then we have esp32 here it is as you can see it's detected esp32 also with the help of USB web camera we create our own custom object detection model on latest Raspberry Pi book War operating system the 64bit work version Let Me Again mention here because right now I am recording on the same Raspberry Pi that's why the detection is little bit slow so now a detect 1. Pi for camera module same way just comment default module line and uncomment custom model line which is default is equal to best. TF this is what our model line uh model name then save it and now te 1. Pi it will start our camera module and then we have detection so friends as you can see it started my Raspberry p camera module and if I show the ardoo board as you can see it's detected ardino no then we have here esp32 here it is as you can see it's detecting esp32 also so we successfully create our own custom object detection model most easy way on lest Raspberry Pi OS book War remember one thing in real scenario you need more than 30 images simple so 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: 14,668
Rating: undefined out of 5
Keywords:
Id: 3YqbO2AlepM
Channel Id: undefined
Length: 48min 15sec (2895 seconds)
Published: Mon Nov 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.