Train Object Detection Model with Detectron2 on Custom Data

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to my YouTube channel my name is B ahammed and I'm your host so guys in this video we'll be learning one amazing uh uh framework called detector true so as of now we have seen lots of object detection uh task with the help of YOLO but uh I'm going to introduce this particular actually framework called detector 2 so this is the research from Facebook side okay so they have implemented this particular uh framework called detector 2 with the help of detector 2 actually you can perform object detection image segmentation as well as key Point detection so here you can use different different object detection backbone you can go with fer rcnn even there are so many actually back Buon is there I'll tell you whenever I will show you the model zo so in this video what I'm going to show you guys I'll I'll use my custom data on top of that actually I'll be fine tuning one first RCN model okay first RCN Network with the help of this detectron 2 um so it would be one amazing video altogether if you don't know detectron 2 and if you are having issue with the setup and all everything uh I I'll will show you like how to do it and all okay I already prepared one notebook for you so let's see like how we can do it but before that first of all let's visit the detecton to official GitHub and try to understand uh what exactly this provides now guys uh if you just search in Google like uh detectron 2 okay detectron 2 uh so you'll get the official GitHub of the detecton 2 so let me open and as you can see this is the research from the Facebook site they have implemented this particular framework and here is the detecton 2 detecton 2 is a Facebook AI research uh Next Generation library that provides stateof the art detection and segmentation algorithm uh it is the successor of detectron and mask rcnn Benchmark it supports a number of computer vision research projects and production application is the Facebook so guys what this Facebook did actually they implemented another actually like very old like Library called detectron okay it was detectron one then then actually they introduced this detectron too but there were some issue with the detectron so so people don't use this detectron okay so instead of that you need to use this detectron too and here if you see it can perform key Point detection image segmentation as well as the object detection okay so these are the task actually you can perform even it has lots of uh actually different different model if I go to the model zo so detector to model to uh as you already saw detecton 2 provides lots of models here you can work with see you have Coco object detection based line here you have fter rcnn backbone okay as you can see these are the different different model okay you can use then you have Retina net you have rpn first first CNN okay then you have Coco instance segmentation so this is for the segmentation model these are the model you can use for the segmentation then if I go below so you also have something called keypoint detection model let's say if you want to perform keypoint detection you can also use these other the model it can also support panoptic segmentation okay so these are the models are available so that's how actually it has uh it is having different different model architecture you can load it as part your requirement as per your task so in this case actually in this particular video we'll be doing the object detection so that's why I'll be using this particular U go object detection Bas line that means this particular model okay and here you are having first model so from this are the model you can use any of the model I'll tell you how to select the model you can uh either directly download either you can get the link and you can uh download from The Notebook itself okay both it is possible so this is the GitHub introduction of this particular U detector 2 guys I hope you got the idea what is detector 2 and how we can use this particular detector 2 detector 2 is a framework it's a library it provides lots of functionality to do uh to do the object detection and you can load different model okay with the help of that but previously we used YOLO YOLO is an algorithm as well as the framework okay both you can do it okay all together in one library now uh here I already prepared one particular notebook guys custom object detection uh okay here let me just write custom object detection detection uh using detector tool okay Us in detector 2 so this is The Notebook so first of all you just need to connect this particular notebook so let me just connect this particular notebook book here and make sure you have selected GPU from the runtime so so here if you see I already selected GPU from the runtime I'm having a premium collab that's why can access this V1 but if you're having free collab you can also go with T4 GPU it's completely fine now see guys it is connected now what I will do first of all you need to install this particular detector to dependency okay so for this these are the command you need to execute okay so this is a complete notebook I will share with you so if you have any kinds of problem statement you can use this particular notebook only you just need to change your data and everything will remain same okay so it may take some time guys uh this installation takes time so I'll wait for this execution okay once it is done you just need to restart the r time okay so let's wait uh once this execution is complete I will come back uh so guys as you can see my execution is completed now what I uh what I need to do I just need to restart the run time so click on the run time and here you will get restart session so it will just restart the run times then you will be able to uh work with uh these are the libres okay so let me uh so let's wait uh once it is connected I think I can execute see it's connected now just import these are the libraries and if it is importing correctly that means everything is fine okay so guys as you can see uh it is importing perfectly that means everything is fine so detector 2 provides two kinds of engin so one is like default predictor and that is like default trainer okay so if you want to find you if you want to let's say uh uh train on top of your custom data at that time you can use uh this default trainer and if you want to do the inference you can use default predictor I will tell you okay as of now I imported default predictor below whenever I will do the training I will import the default uh trainer as well okay so these are the thing you need to import then after that you just need to get your data okay you should have your custom data ready and if you don't have data uh okay so what you can do uh you can use uh roof flow.com so roof flow provides actually lots of Open Source uh data set okay for the object detection image segmentation G Point detection uh all kinds of date actually you will get from the Overflow universe so you should have one account so so so here let me sign in with my account and I will show you like different different data actually you can use so here is the universe guys just click on the universe so it will open up the entire universe and here you will see different different data so in this particular example I'll be using something called Chase data okay so Chase uh Chase paches okay Chase PES this this data I'll search it you can search any kinds of data you'll get it so this is the data I think uh let me show you uh so yeah guys this is the data actually I'm going to use and here you are having images as you can see and with that you are having different different levels so these are the level actually you have at pH kale pona and uh vit okay so here you can download this particular data set just click on the download and it will redirect to you uh that particular page and here you can select the image see here you can uh export the data you can also download as a z file either you can uh uh like uh get the link and you can also download from The Notebook itself but thing is like here you just need to change the format okay format of the data and if you're having your custom data guys uh which is not available let's say uh in this particular roof flow at that time you need to annotate that particular data because rlow provides all the data and it is already annotated okay all the data is already annotated here you can directly import it and rlow also provides uh interface okay uh these kinds of annotation interface so you can upload your data there and you can also do The annotation okay so for this actually you can refer this particular video I created training YOLO V5 on custom data set so there actually I showed you how to annotate the data that's why I'm not going to show you again you can watch that particular recording okay and there actually I showed you how to upload your data in the Overflow platform and how to annotate the data and how to download it okay so here uh just for Simplicity I will use the available data from the Overflow itself so here what I will do and make sure see there actually I was using uh y yellow format data but here we are using something called detectron 2 uh like framework right and detecton 2 framework supports actually Coco okay Coco format so that's why your data format should be Coco so as you can see you need to select this Coco format then uh click on this show download code and click on continue okay if you do it so it will give you different different things you can uh download from the jupyter you can download from the terminal okay you can also get the raw link so I'll click on the terminal and this is the link guys you need to copy okay so this link you need to paste inside the notebook as you can see this is the link you need to paste inside this particular notebook okay see all the link I pasted here now it will download that particular data from this particular uh URL and it will uh download a z file after that it will unzip and it will show me the data okay so let me uh show you the data input here so guys see this data is downloading now once it is done it is extracting now if I refresh see my data set is available so 10 test folder as well as my training folder and guys it has one annotation file uh Coco annotation called Json as you can see let me show you annotation the juston is there see this is one so this file contains the entire annotation information okay and we call it as Coco format so you can see that particular video how to annotate and uh how you'll get this particular file okay so I have successfully imported the data set now what I need need to do see in detecton 2 there is a concept called Data registration okay so first of all you need to register that data so here we don't load the data okay uh in the disc okay in one time we just registered the data whenever I need that I just call with the name and it will give me the data okay so I just need to save this data as a metadata so for this here you need to do register Coco instance okay so this is the class I imported now inside that you need to provide the name here you can give any kinds of name I have given my data set train and my data set test and here is the location I have given so this is The annotation location you need to give it is present inside my training folder and this is present inside my testing folder and what is the location this is the location content inside my train and test okay that's it now let's register our data see data registration is done now if you want to visualize your data so what you can do you can call with the name okay now I don't need to relocate the folder location because already all the information has in this particular registration now I'll call with the name let's say I want my training data I'll just call with the my data set train and here I will get all of the data instance okay as a dictionary then here I can write a for loop with the help of for Loop I'll fet the data and with the help of open CV I can show you this particular image okay on my terminal now let me show you see guys so here I I I want to see three images so that's why it is printing three images as you can see with the label actual label okay that means I'm able to successfully uh uh like plot the data as well now your final training will start okay and and see guys uh if you're using this detector 2 like it's like very easy to use okay it's just a plag and play kinds of notebook uh with the help of very less line of code you can train you object detction model now here is the code guys for trainer as you can see I'm importing this default trainer uh engine after that these are the configuration need to set and by default actually this code will provide you by the detecton 2 okay this uh if you go to this particular repository you will see these kinds of notebook so I have just copy pasted these are the code from there only okay so you can keep this particular notebook and you can execute so only uh here you just need to change the model as you can see here you need to change the model so how to change the model go to the uh model zo let's say you you are doing this uh uh object detection so here you can change the model see I'm using this particular model here let me show you I'm using fer rcnn R50 fpn this model first in R50 fpn R50 fpn R50 fpn this is the model see this model I'm using if I click on the model so this is the model Bas line now here you can copy this particular link okay this cop uh copy this link and here you just paste it okay here you just past it so here you just need to Define you are doing Coco detection okay not a segmentation so it will automatically uh get to know you want to perform detection not a segmentation after that the same thing you need to give it here and here is the iteration okay maximum iteration so let's give uh 500 iteration here uh you can also increase the iteration because this is the default iteration I'm giving but whenever you are training your actual model make sure you are uh increasing this particular iteration size okay now everything is fine you don't need to change anything now you can start the training okay see this is the thing only you need to configure now it will load your model if this model is not available it will download and logging is very good here guys it will uh tell you all the logs like uh how many pox is running what is the losses and everything it will show see and it will create one folder called output inside that output it will save all the uh metrics and your model OKAY save model now see guys my uh iteration has started and iteration 20 I can see okay because see it will show you the iteration after every 20 P okay that's why you can see 19 uh 32 because it has started from zero that's why and this is the total loss this is the class loss this is the Box loss okay all the losses you can see here now let's wait so once training is done I will come back and I'll will show you uh so guys my trading is completed and uh here in the output folder you will see uh your model as you can see this is the model final pth that means this is the model and uh here you have some of the metadata related your logs now what you can see you can also uh print the logs okay with the help of this tensor board you can launch your tensor board and it will Lo load all the logs like what is the training losses what is the Box losses what is the accuracy everything you can see from this particular tensor board so let me load uh so guys as you can see this is my tensor board logs and here you have uh like date time and if you want to check it with different different see this is the epoch per uh ATA seconds okay this the seconds I think and if you want to check the losses so here is the loss loss rpn classes so your uh epox is increasing also loss is decreasing okay so that's how you can check out with different different loss okay see this is the total loss EPO is increasing Closs is also decreasing that means my model is learning fine now what you need to do you need to load this particular model and we'll be doing the inference okay on top of our testing data so let's load this particular model so I load this particular model and here you need to set the confidence score like what would be the confidence score for your model it will uh predict uh that is the actual class okay you need to set this parameter here so I kept uh the default parameter 0.5 you can also increase and decrease as per your requirements now here guys first of all I need to load my testing image okay so here I'm calling with my test image I think you remember I already registered my testing image okay then after that uh with the help of this uh for Loop I'll be loading my model okay as you can see loading the model and inside the predictor I'm giving my uh here I already defined my predictor okay after loading the model and here I'm giving the image okay one by one and uh let's see the prediction whether it is able to predict or not see guys successfully it is doing the prediction as you can see uh it is predicting okay see it's predicting uh okay that means everything is working now what I will do I'll just uh quickly stop the execution uh because there are so many image in that testing folder I don't want to print all of them okay done now if you want to do the evaluation okay on top of the testing data so you can execute this particular code so it will show you the entire Evolution Matrix so it will load the testing data it will load your model and it will calculate the uh matrixes okay so let me show you so guys here you got your final uh uh results so this is the a position uh you you got here so a prion that means uh everything is learning fine here okay all the classes having uh uh almost same average position okay that means all the class is learning fine now if you want to save this particular uh CFG that means the configuration model configuration you can save it okay with a yaml file because going forward whenever you will be creating web application you need this particular file okay whenever you want to load this particular model so in future I'll also show you how we can create a web application how we can do realtime prediction with the help of this detecton to okay so for this uh please subscribe to my channel and share this video with your friends and family and if you like this particular video just uh give a thumbs up okay guys so this is all from my uh site actually and this is all about our custom object detection with the help of this detecton to I hope you like this particular video so guys thank you for watching this video and I will see you next time
Info
Channel: DSwithBappy
Views: 4,710
Rating: undefined out of 5
Keywords: detectron2, detectron, object Detection, computer vision, AI, artificial intelligence, object detection using detectron2, custom data, detectron2tutorial, customdatatraining, objectdetectionmodel, customobjectdetection, detectron2training, machinelearningtutorial, computervisiontutorial, aimodeltraining, deeplearningtutorial, customdataset, customobjectdetectionmodel, objectdetectionalgorithm, trainingdetectron2, modeldevelopment, detectron2customdata
Id: 5dDN_uViEAU
Channel Id: undefined
Length: 15min 48sec (948 seconds)
Published: Tue Feb 27 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.