YOLOv5 training on Custom Dataset | PCB defects detection using YOLOv5 | Google Colab | @mbdnotes2423

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to my youtube channel mbd notes in today's video we are working on defects detection in pcb circuits using yellow e5 so this video is a response to this comment without wasting your time let's do it first of all let's open jupyter notebook here we go first of all we need a data set to perform training so as you can see here that i got a kaggle.com data set url you can visit this link and here you will get a data set related to pcb defects so this is a complete data set of different types of defects i have already downloaded this data set as you can see here you can also download this data from here i will also upload this notebook in my github repo and share the url with you you can find this in description so when we have downloaded this data set we need to extract it over here so let's do that so we got our data set extracted over here i don't need this zip file anymore so let's delete this so let's open this folder and as you can see here there are four folders and one file so this python file we don't need this rotation folder is also not required these three folders are required for training and testing purpose so what's inside these folders let's see that this is the image folder in which we got images of six categories of pcb effects as you can see here so let's see our annotations we got our annotations but as you can see here that these files are xml files actually but we need text files to train yellow v5 model on this data set so we need to convert these xml annotations into text file as the format we need like this one so how would we convert these external files into text files according to yolo format for that purpose we got a package as you can see here and this is a xml to text package we need to install this and then run this command to convert our xml annotations to text annotations according to yellow v5 format so let's open this github package so in this github as you can see here we got some python files which we will be using too convert these files actual files to text files okay so let's clone this wrapper on our computer let's do it over here okay so i got this xml to text folder and in this folder you can see some files but as you can see here that there is a requirements file over here this is requirements.txt file we need to install these requirements so open command prompt in this directory and run so as you can see here that it says that requirements are already satisfied but this is because i have already installed these requirements in my system so these requirements are satisfied so we can move on to transfer process you can see that this is the xml folder in this folder we will copy our xml annotation files and this is the output folder so let's delete all files in both of these folders and copy our annotations in these folders so let's copy all of these we have successfully copied our xml annotations in this folder but before moving to the conversion process we need to specify the classes names in this class is the txt file so let's open this file so let's copy all of our classes into this the first one is missing hold let's open some file as you can see here this is the name of glass over here so let's copy this missing out class and paste it in the first row there is a mouse byte class copy this name as well and paste it on the second line now we can run this command but before that we need to move into this directory in which we are working so let's import os os dot cn directory to this xml text directory okay we need to change these backslashes to forward slashes so when we are in this xml2 txt directory we can directly access all these files this python file this txt file this xml and output folder so let's run this so it took around two to three seconds and it is completed so let's see that in code folder we got our same folder as we got the example notations so as you can see here that we have our text file so now we have our text so now we have our annotations in text file which are perfectly according to the yellow v5 format so let's copy all these annotations let's delete these old xml annotations and paste our text annotations and also we don't need this xml to txt folder anymore so let's delete this too now we are done with the annotations so we downloaded our data set and we converted the xml annotations to our text annotations so these exam annotations we got from kegel.com but if you don't have any annotations so do you can directly move to you know tell your images manually using some tools like make sense dot ai you can watch our previous yellow v5 video in which we have demonstrated that over to annotate your images so now our images and annotations are ready so we need to arrange these images and annotations according to your file directory structure which is like this structure so we need to have a data set a parent folder in that folder we need to have two a folder one for images and one for labels and in both folders we need to have training and validation folders so as you can see here so let's create these folders over here this is a data set parent folder in this folder we need to create two folders one is for images and the other is for labels so we got these directories according to yellow v5 format so let's move our images into these directories but for that purpose we need to maintain a ratio of maybe eighty percent of images will be the training images and twenty percent of images will be the validation images you can also change this ratio to maybe 70 or 30 percent or 65 to 35 percent ratio or maybe 75 to 25 percentage or we will divide it into 80 to 20 ratio so let's uh so first of all let's combine the images and text files so let's copy all these images and move it into these annotations so when you will open it you will see that every image will have a separate text file with that so now we need to move these images and annotations from this annotations folder to this dataset folder and for that purpose i got in this function we will be using this function to move our images from this annotation folder to dataset folder so let's do that first of all call this function we need to provide it these parameters so first this is the images which is uh data set images train path this folder path okay first but before that we need to move in this directory from where we can access these folders so we need to move in this parent directory this directory okay so we need to change the directory os dot change directory to this parent directory so can we can so that we can access so as you can see here that we are now in this parent directory so we can directly access these paths from this directory so let's copy all these parts so in the second parameter we need to have images validation path which is in the data set in this folder and this validation path number three we need to provide the labels plain path this is the labels and this is the training path change these backward slashes to forward slashes and there is a label validation part which this one and this is the data set source this is the folder in which we have our images and annotations so so this is the annotations folder which which is having the images and annotations but we will not uh do this at once we will transfer our images one by one from all of these so that we can maintain our ratio first of all we will move this missing whole folder so let's run this it says that choice is not defined so before this function we need to import some packages so let's run this function again and call this function so in this folder there are 92 images for training purpose and 23 images are for validation purpose so let's see that if we got our images so as you can see here that there are 92 images and there are 23 images similarly we need to move all of these folders so this is the second mouse white folder so we just need to change this folder now let's run this function so we moved all of our images from here to this dataset folder in 80 to 20 ratio so in training folder we got five five two images in a validation folder we got one three eight images so now this dataset folder is ready so we don't need this annotation folder anymore let's delete this so now we have only two folders one is dataset which is completely according to your file format we got our annotations converted from xml to text file and we got our test files as well which are 12 images now we can open our google collab notebook to perform training so let's create let's create a new notebook over here now upload our data set to our google drive so that we can access it directly from here so we need to create a zip file of this data set folder let's let's rename it to dataset pcb so that we can identify it easily and now we can create a zip file so when our zip file is ready we can directly upload our data set to the google drive so as you can see here that our data set is uploaded now we can perform training so first of all we need to connect our notebook to the server using gpu so in this edit menu you need to open this notebook settings and over here you need to select gpu and click on save now to click on connect so first of all we need to integrate our google drive with this notebook because we have uploaded our data set on the google drive right these two lines of code and so you can see that our drive is mounted over here so we can access our data set from this now we need to extract this zip folder in our google drive so let's copy the path of this data set and run this command unzip paste the path for your data set over here now you need to write hyphen b and after that you need to write the path of your location where you want to extract your data set so i will just extract it in this content directory so as you can see that we got a new folder pcb data that and in this folder we got our data set available now we need to clone the github wrap of yellow v5 so basically 5 directory which is this one you need to make sure that you are in this parent directory for that purpose i will write this os dot get cwd function so it says that we are in the parent directory which is the content folder so we can clone over here as you can see here that we got our yellow v5 directory so move into this directory using this cd yellow v5 command we are now in this regular e5 directory in this directory you will see that there is a requirements.txt file you need to install these requirements using peak command so our requirements are successfully installed now we need to specify the location of our data set and for that purpose we need a dataset.yaml file as you can see here that i have already created a dataset.aml file but this is for another project so we need to edit this for this dataset so we need to specify the location of our data set so we will put this dataset.aml file in this yellow v5 directory so from this directory we need to come out of this yellow v5 folder and go into this dataset pcb folder so data set pcb and forward slash we will see that we successfully specified the path of training images and similarly we will specify the path of validation images these two variables are required and here you need to specify the names of all of your classes but remember that you need to specify the names according to the index of your annotations so we see how annotation was on the first index mouse byte was on the second index so we have six classes over here so we need to write this parameter as six this parameter nc specifies the number of classes we have so our dataset.yaml file is ready now we need to upload this dataset.yaml file to your e5 directory on the google app so just drag this file and drop it in this directory so here you got his file now we can successfully run the training so this is the training command we need to specify the training.py file this is the image parameter in which we will specify the size of image this is the batch size which is 16 and this is the number of ebooks ebooks are the number of iterations like how many times your your v5 model will look into your data set so let's specify this maybe uh 50. uh this is the dataset.yml file which is this file which we have just uploaded and invades parameter we need to specify some free trade weights you can also see other models in the training section these you can use any model 5x is the largest yellow v5 model and 5n is the smallest model so you can specify any model over here so we are currently using yellow e5s and there is one more parameter which is name you can specify the name of your current experiment this is totally optional so far i will specify my project pcb first okay so now just run this training command as you can see here that our training is conducted and results are saved to runs train and pcb first folder so let's check out there so here as you can see that our training results are saved so let's see the confusion matrix results are not that much satisfactory but we got our results maybe it is because of number of ebooks we need to uh run this command for at least maybe 300 epochs so these results are for only 50 epochs so which are not that good let's see the pr curve so as you can see here that it is also not as good as expected the overall accuracy of all classes is 57 which is not good but increasing number of epochs may improve our results so you can try that so let's try some validation and prediction so this is the data set we provided let's see the one which is predicted so as you can see that a lot of detections are missing in this within this image and in this image there is no uh detection so results are not that good in these number of ebooks you need to run this for at least maybe 300 equals so now as you can see that i have traded my model once again by increasing the number of epochs up to 300 so let's see the results once again our training is completed and results are saved in this directory let's see that so as you can see that we got pretty good results by increasing the number of epochs so let's see the pr curve if you see the pr it is also pretty good we got a 93 percent of accuracy for all classes now let's see uh that validation results so this config matrix is for the validation you
Info
Channel: MBD Notes
Views: 9,936
Rating: undefined out of 5
Keywords: computer vision, PCB defects detection, object detection, yolov5, yolov5 tutorial, object detection with yolov5, google colab, goolge colaboratory, PCB defects Detection with Yoolov5, Printed Circuits Boards Defects Detection
Id: LB9SklRNDUA
Channel Id: undefined
Length: 24min 49sec (1489 seconds)
Published: Sat Aug 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.