YOLOv8 COMPLETE Tutorial | Object Detection | Segmentation | Classification

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to the channel in today's video we are going to run YOLO V8 which is faster and more accurate than YOLO V7 YOLO V8 is trained for object detection image segmentation and image classification tasks we will run all of these tasks in this tutorial the timestamps are given in the description let's get started first we need to set up environment for YOLO V8 and install required libraries I am using Anaconda so let's open add-on contact prompt and create a new environment called YOLO V8 with python version 3.9 hit enter press Y and hit enter again once the installation is done activate YOLO V8 environment that we just created now install ultralytics Library by command pip install ultrolytics it's going to take a while to install all the dependencies notice that it has installed torch 1.13.1 without GPU support we can verify that by running python then import torch and then run torch.cuda dot is underscore available it says false so Cuda GPU is not detected we can also print torch version by command torch dot underscore underscore version underscore underscore and it's 1.13.1 CPU version if you plan to use CPU you are all set but for GPU support let's go to pytorch official website and then to get started page scroll down we are going to install Pi torch 1.13.1 on windows with Pip on python with Cuda 11.7 which is the latest version at the time of making this video let's copy this command go back to Anaconda prompt and paste here add minus minus upgrade parameter in the command and hit enter it will download and install pytorch with Cuda support and uninstall previous CPU version we can again verify if GPU is detected let's run python import torch and then run torch dot Cuda dot is underscore available this time it prints true so we are all set to run YOLO V8 on GPU all right to run YOLO V8 I have these two videos and one image here you can use any image or video you want YOLO V8 can be used directly from command prompt or we can write python code let me first show you how to run YOLO V8 from command prompt directly in command prompt type YOLO then task equals detect which is for object detection then mode equals predict and then we need to Define model name you can find the model names on the official YOLO V8 GitHub repository we have all these versions available for object detection all of them are trained on 640 cross 640 resolution and of course the models with lower number of parameters would be faster but would have lower performance for demonstration I am going with Nano version so let's type YOLO V8 and Dot PT as model name then we need to Define source which will be one dot jpg in this case and if we hit enter the model will be downloaded automatically and the output is stored in runs slash detect folder here we have it if we open this file we can see that person is detected but there are some false positives like this backpack and this person over here but notice that their confidences are very low so we can add another parameter to the command conf equals 0.5 and now if we run it only those pounding boxes will be drawn which has confidence of 0.5 or higher we can see that in this output these bounding boxes with low confidence are gone now if you want to show the output in real time you can set the parameter show equals true and it will show the output but in the case of image only for one millisecond so maybe ultralytics should bind it to a key press instead of closing it automatically and if you need to save the bounding box information you can set save underscore txt equals true and now if we run it we can see that the labels are also stored along with predictions if we open this label file we can see that it has class label and bounding box information in Yolo format if you want to save the cropped object you can set the flag save underscore crop equals true and now if we go to the output directory we can see all the crops for person class but these have the bounding boxes and confidences printed on the border which should be fixed I believe maybe alternatics would do that in one of their future releases but we can remove the labels and confidences with two more Flags hide underscore labels equals true and hide underscore conf equals true and now if we run the command we can see that the only bounding box is there labels and confidences are gone now if we want to run object detection on videos well just replace this source with video name let's run for cars.mp4 let me remove these other parameters and set show equals true if we run this we can see the output in real time and this output will be stored on the hard drive as well as this is nano version there are a lot of false positives you can use any other larger model to get more accurate results if we go to this new subfolder we can see the output video here as well so now what if you want to run object detection on webcam well you can set the source to zero for internal webcam or rstp address for your network webcam or you can use some directory that have multiple images or videos to run object detection in just one go so this implementation is really flexible now let's run image segmentation using YOLO V8 let me delete this previous output folder for image segmentation we need to issue the following command YOLO task equals segment mode equals predict and for model we will use the name of segmentation model now if we go to YOLO V8 official repository there is this section for segmentation models let's say I want to run YOLO V8 Nano for segmentation to get the file name I am going to copy this link address and paste it in a separate window at the end you will see this dot PT file name just copy it and paste here in the command and let's set the conf to 0.5 if we hit enter this time the segmentation model will be downloaded automatically oops I forgot to mention the source image let's add Source equals one dot jpt to the command and if we hit enter the output will now be stored in runs and segmentation subdirectory if we go there we can see the predicted segmentation output again we can set height underscore labels equals true and hide underscore conf equals true just like before and it will output segmentation with bounding boxes only maybe Alternatives should consider adding height underscore B box option as well to get the segmentation only without any bounding boxes now if you want to save the polygons information for this segmentation map you can use Save underscore txt equals true and we can see that now a text file is also stored along with the output with the class label and the polygons for each person in the image now to run the segmentation on videos just replace this source with video file name cars.mp4 in this case and we can also set show equals true now we can see segmentation in real time and the output will also be stored on the hard drive just like in the case of object detection for classification similar command would be used YOLO task equals classify mode equals predict and model name can be obtained from official repository I'm just going to copy this link and paste here then copy the file name at the end and paste in the command now Source equals 1.jpg this time we will also mention the image size on which this model was trained as you can notice in the repository that for classification models the image size is 2 to 4 cross 224 so let's mention 224 here and hit enter now classification model is being downloaded and the output will be stored in runs classify folder if we open this it should have top five labels along with their probabilities so the probabilities are fine but the labels are in default imagenet format and this might need post processing to make them human understandable maybe ultralytics will fix that in the future versions as well so now to export the models in different formats such as onnx or TF Lite we can use this command YOLO mode equals export task equals detect which means we want to export detection model and model equals YOLO V8 and Dot PD then we need to define the format in which we want to export so format equals one and X and you will see that the respective on the next model is saved here similarly for segmentation model just change task to segment and the model name to YOLO V8 and SEC dot PT hit enter and this time the own NX file for the segmentation model will also be saved you can also use DF Lite as the format but that is not yet implemented so you'll get not implemented message for now maybe in future versions this capability will also be added so now at the end let's see how you can do all this in Python instead of command line I am going to create an empty file called predict.py and open it in any text editor then from ultralytics import YOLO then initialize YOLO with the model name that you want to use let's use medium versions of the models this time so I am going to copy the model URL from here paste here and then copy the file name and then paste in predict.py file now the model is initialized we can call predict method this method takes all the parameters of the command line interface let's mention Source equals 1.jpg save equals true conf equals 0.5 and save underscore txt equals true let's run this python file by command Python predict.pi and here are the results just like before along with the saved text file now to export the model to onnx Let's comment this predict line and add another line model dot export format equals 1 and x and here we have the on NX file for this medium model as well to run object detection on videos just change source to your video file cars.mp4 in this case and let's set save underscore txt to false and show equals true if we run our python file now it's going to run on the video notice that we are not telling the task type in Python this is automatically inferred from the model file name run yellow V8 segmentation just copy any segmentation and model file name from the segmentation section and paste here let's change the source to one.jpg and save equals true if we run our predict.pi file now it will automatically download the model if it's not already present in the directory and then perform the segmentation and finally for classification just copy file name for any classification model paste here save the file and run it again there you go the output will be stored in runs folder with that I think I am done in our next video we are going to learn how to do custom object detection using YOLO V8 if you have learned something of value today hit like And subscribe to the channel to watch more videos like this consider a support on the patreon to help the channel out I will see you next time [Music] thank you
Info
Channel: TheCodingBug
Views: 42,817
Rating: undefined out of 5
Keywords: yolo v8, object detection, image segmentation, image classification, yolov8, ultralytics, yolov8 windows, yolov8 linux, yolo v8 windows, yolov 8 linux, yolo object detection, yolo 8 object detection, yolo 8, yolo8, yolov8 tutorial, yolo v8 tutorial, yolov8 object detection, yolov8 image segmentation, yolov8 egmentation, yolo 8 segmentation, yolo v8 image segmentation, official yolov8, official yolo v8, yolov8 classification, yolov8 image classification
Id: 75LI9MI9eEo
Channel Id: undefined
Length: 13min 4sec (784 seconds)
Published: Mon Jan 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.