Object detection app using YOLOv8 and Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is Ari and welcome to my channel so guys in my today's video I'll show you how you can create your mobile application object detection mobile application using Android so whenever you want to create a object detection application the first thing is you need a trained model which can detect objects so for my today's tutorial we will first train our YOLO V8 model to detect custom classes I'll show you how to train your model then how to convert your model into TF flight format why we need this tfight format model because this uh format will work with your Android app so first step is we'll train our object detection model after that we'll test that model and in third thing is we will convert that pytorch model which is the default model type you get when you you know train your model using ultral XS so you get a py model so we will convert that py model into a TF light for uh TF light format and and then we will use that TF light model into our Android app okay so let's start so guys here you can see this GitHub repo the link is given in description section just clone this GitHub repo and here you can see this one this is the Jupiter notebook which will show you how to uh work with the custom data set how to train your custom model okay so let's see this file first so I have this file in my local machine over here so here I'm importing the ultral litics package if you already have ultral litics installed then this code will work otherwise you need to install the ultral litics package first and for that you can write pip install ultral litics and then your environment will be ready using which you can train your model okay so here I'm importing the ultral litics pack P Ag and this here I'm loading the YOLO V8 pre-train model which is trained on Coco data set so I'm not training my model from scratch so what we are doing is we will use this pre-train model and then we are fine-tuning it with our custom data set and here data. yaml now let me show you the data set on which we are working okay so let's open this data. yl file first so this is my data. yl file and here you can see we are working on a custom data set and the data set have four classes and these are the name of those four classes fork knife plate and Spoon so what we are doing today we are building a custom object detection model which can detect these four classes okay and this is the path of my training images and here we have given the path of our validation images so I have a data set folder let me open that here you can see this is my data set folder and this is the data. yl file which I've just shown you and this is the Jupiter notebook which uh in which we are training a model okay and data set inside data set we have two folders train and B inside train we have images and labels in the same way inside Val we have images and labels inside images you will see all the images related to the classes which we are going to train our model on and inside labels you will see their corresponding uh labels which are in text format okay so this is our data set and then let me open this Jupiter notebook again and just here right I want to train this model for 100o and the image size I want to set is this device zero means I want to train my model uh using Cuda using GPU here you can see the detail when I run this uh cell uh this is my GPU and this is the Cuda version I'm using and this is the torch version and I'm working on Python 3.1.6 and this is the ultral litic version I'm using and after training you will see a runs folder inside that detect folder and in train three folder you will see your trained py toch model okay so let's see that so here this is my runs folder detect and this is a train folder here after training you will see the confusion Matrix and all the related files over here okay and inside weights you will see the best DOT PT and last dot PT weight okay so this in this part I I will show you in some time how we are going to get this part but the Step which I have shown you over here this one when you'll run this cell with after running this cell you will only get these two things best. PT and last. PT okay so you have your train weight now now let's test our model if a model is able to detect the spoon fork or uh a plate and knife okay so for that we are loading our custom model and okay before testing our model this script is used to validate your model and this is how you can perform the validation if you want to test on validation data how your model is performing then you can validate your model like this and here you can see the results here now I'm showing you how to make predictions using this trained model so our trained model is stored at this location we are loading our train model and I have a test images folder in that folder I have multiple images on which I want to perform testing and save true simply means it will save the predictions in the runs folder and confidence score and this you can provide when you'll run it the results will get stored and let me show you the results just go here inside detect you can see the predict three open it and let's open the output see it is detecting folk and Spoon in the same way this is the second image here also it is detecting Fork and Spoon and here it is detecting this as a wrong class name so you can further improve your model by you know increasing the data set or by training your model for more EO right so today I'm just showing you the demo like how we are going to use this custom model uh into the Android app okay so no so that's why I'm not focusing on the accuracy of the model right now all right so now we have our trained model and we have tested our model now the next thing is to convert this model into a TF light and converting your model into t TF light exporting your model into TF light is very easy using the ultral litics package so you just need to load the model first the model which you want to export in some other format okay so we have a best. PT model we want to export it into um TF light okay because this TF light will work on our Android app so we model. export and format TF light just run this cell and after that you you will see that your TF light model is stored at this location see train tree weights inside weights we are going to get this folder and inside that you will see your TF flight model okay now let me open this location detect train three weights now you will get these this folder and this file when you'll execute this cell the export cell okay and here inside it you will see the TF light model now you will copy this model from here and this model we are going to paste in our Android app code okay now let me show you how to do that and guys let's go back to the repo first I have explained you this file using this file you'll get a t TF FL uh model now in this folder we have the Android app code like this these kind of files and folders you'll get under it now I'm going to show you how you can use um Android how you can create an Android app okay so under this second section step two guys here just what you need to do is just open this Android app folder this folder and inside it you have to paste your TAF flight model in the assets folder okay now where is assets folder you can see the location of assets folder from here let's go back go there okay let me open that so our code is here step to Android app this is my Android code this is the code which I've shared on uh my GitHub page Okay click on this app and then Source after that Main and here you will see the assets folder inside this folder you have to place your model so I have renamed my model to this model. tfight okay which model I have renamed okay let's open that also let me open that folder so let's go in e Drive and then here so this model okay I have pasted this model over here and then I have renamed it to model. flight okay and then we have a text file this labels text file inside this labels file you need to write the name of all the classes like this in this format okay so these are the two things which are required so this is the first change we have done and after that next thing is see rename the path of your model and label file in constant. KT file now where is it you can find it at this location okay now let's let's open this let's go back to here come out of this assets folder and then click on Java com here and then this is the file now you can open this file let's open this file so here you can see model. tfight and then labels. txt so guys if you if your model name is something else then you have to rename that file over here okay and if your labels is suppose you have a label file with some other name then you have to provide the name of that file over here okay so this is the next change which you need to do these are the only two changes which you need to do now our next task is to download the Android studio and install it okay so for downloading the Android Studio you can click on this link and then you will be redirected to this Android um page here just install this download this latest one okay so I have download downloaded this exact version so download this and once you download it just uh start with the installation step and you just need to follow the prompt and you will see what next steps you need to take and following that you can uh install the Android studio now once you install the Android Studio we will open the Android studio now let's open the Android Studio so so when you open the Android Studio for the first time you will see the options like like new project or you want to open the current project okay so as we already have the code where our code is so I have provided the I have provided you the code and the code is presented this location right so we are not creating a new project so you will not click on this new you will click on open because we want to open this code using this Android Studio let's click on open and then just go to the location where your code is so I I my code is over here step two Android app okay so click on this and then click on okay so our app is loaded here guys here now you can see app no devices we need to connect the device on which we want to perform the testing so let's do that here you can see this phone okay so this is my Android phone which I have connected with Android Studio using USB and if you want to connect using WiFi or other way you can uh these are the options you can connect it from here okay so in my case my phone is this and my phone is connected now now we will just run the app by clicking here right just click here here you can see it is connected okay so now our app is connected now let's test the app so here you can see the output our mobile app is detecting the spoon and Folk
Info
Channel: Code With Aarohi
Views: 3,818
Rating: undefined out of 5
Keywords: yolov8, objectdetection, computervision, ai, artificialintelligence
Id: dl7rCmvIyiI
Channel Id: undefined
Length: 13min 50sec (830 seconds)
Published: Sat Apr 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.