Training YOLOv8 with KerasCV on Custom Traffic Light Dataset

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
last week we had overviewed the K CV library today we are going to train a YOLO V8 model on a custom data set using K CV hey there welcome to learn open CV we are using the small traffic light data set by thinklab training a model on these images is good for Adas which is Advanced Driver assistance systems there are around 4500 images and the annotations are given in XML format now let's take this data set to Google collab and train our model to follow along with me open the blog post Link in description then click on the download code Banner fill your details and hit enter you'll receive an email with the notebook link download it fire up Google collab and let's get started we have a v00 GPU and uh let's start by initializing our environment so we need Keras CV and we need Keras core give it a minute now next are Imports so we need for directory operations XML for you know our annotations tensor flu and caras to train our model requests and zip file to download and unzip our data set then we also need tqdm for Progress pass and uh we import two modules from KV which is bounding box and visualization we'll uh learn more about them later on so let's move on to downloading a data set we use request.get to download our data set so simply run this and we Define a function and then call the function with the URL L then we'll take the data set as a zip file and extract it using this ZIP file Library moving on we're going to set up our data so we going to Define some variables we have a split ratio because our data set is just a bunch of images and annotations we need to split our data set into train and test set so there's a split ratio which is 80% of our training set and 20% images go into a testing of validation set then we have bad size learning rate Epoch Global clip NM and image size so bad size is how much images are going to be trained in one iteration then we have learning rate and Global Clip N which is going to be used in optimizers epox is how many times the model will cycle over the whole data and image size is the image input size which is 640x 640 you should also check out opencv University's free official tensorflow and caras boot camp go to opencv .org /un university/ free courses to know more next we map the class labels that we'll need for training and we also get the part two images and annotations then we'll move on to extracting the bounding box coordinates from The annotation files or the XML files so we do that with this function uh the pass annotation function takes the XML file opens it and then it gets the bounding box coordinates which is Xmen y Min x max y Max then then we also get the class IDs which is according to our previous mapping that we had defined the class mapping that we had defined then we simply call the parse annotation function we get the image Parts the bounding box coordinates and the class labels in a list we convert this list into ragged tensors to use it for our training next we uh split our data set into training and validation set so you remember our split was 0.2 so 80% of data is in the training set and 20% is in the validation set here we actually splitting the data next we load the images so previously we had extracted the bounding Bo coordinates from the XML files over here we are loading the images which is basically you know read so instead of I am read we are going to be using tensor flows read file to get the images in tensors load image will load a single image and convert it to tensors and load data set will take the tensor Lo loaded images and package the bounding box coordinates and the class table together and return all the three then we need augmentations so ker CV comes in built with some augmentations so we have random flip we have chittered resize we have random contrast brightness and gion blur we'll just be using random flip and Jitter Tre size now augmentation is important to introduce variability in the data set this helps model generalize better so we're going to make augmentation layers using K CV and apply it to a train data set now these augmentations are not necessary on the validation set so we're just going to be using the Jitter res size and map it to our validation set now let's just visualize a data set these are what the images look like there are green off green green Green okay Red Light Green Light looks good now this is another helper function which converts dictionary into into tle next we move on to model initialization we get the K cv8 backbone and we Define the large YOLO model with Coco pre-trained weights for the head the weights will be randomized then we Define the model with a number of classes the bounding box format which is xyxy the backbone and fpn DEP now you must know YOLO accepts YOLO format annotations but instead we are passing X-Men y men format which which is crazy which is absolutely crazy and is introduced in K TV then here is our model summary we have 4.1 billion parameters and next our model Optimizer we're going to be using Adam Optimizer and the learning rate which we had defined above and the global clip now combine the model and we can move on to training but before that we need evaluation metrics to monitor we Define a call back function to execute at the end of epoch and we're going to be monitoring map we also using tensor board to log our graphs and finally we're ready to train our model so we're going to call model. fit pass the train data set the validation data set and number of EPO and the call backs that we're using and run but we're not going to train for 75 EPO that's going to take a long time uh we'll just go back and change the number of epochs to one and train for one Epoch and then move forward to validating the model now just sit back relax or you know if you're like me you could just browse some memes so that's it this was our model training this is going to give us horrible results because it's just trained on one Epoch as you can see our loss is so high our M values are incredibly low uh but you know if you increase the number of epoch you're going to get better results next running validation on a train set so we're going to be calling model. predict and pass the images and then again use the visualization model of K CV and call plot bounding box Gallery function pass all these values and you're going to get your results so that's all about training K CV models on a custom data set if you like this video why don't you check out a previous video on K CV overview or other videos in the YOLO masterclass playlist do comment on what you would like to see next and don't forget to subscribe thanks for watching I'll till next time
Info
Channel: LearnOpenCV
Views: 3,051
Rating: undefined out of 5
Keywords: learn computer vision, computer vision basics, what is computer vision, Computer vision tutorial, opencv, learnopencv, deep learning, OpenCV, KerasCV, ComputerVision, KerasAPI, tensorflow, object detection, Yolo, machine learning, yolov8 custom object detection, opencv python yolov8, yolov8 object detection, deploy yolov8 model, custom yolov8, opencv yolov8, yolov8 opencv, yolo deep learning, yolo object detection, yolo v8 custom dataset, object detection yolo
Id: vCT5rFrERaI
Channel Id: undefined
Length: 7min 33sec (453 seconds)
Published: Mon Oct 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.