Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

YOLOv8 COMPLETE Tutorial | Object Detection | Segmentation | Classification

https://www.youtube.com/watch?v=75LI9MI9eEo

>> conda create -n yolov8 python=3.9


>> conda activate yolov8
>>pip install ultralytics

For GPU Support

>>pip3 install --upgrade torch torchvision torchaudio --index-url


https://download.pytorch.org/whl/cu117

----------------------------------------Object
Detection----------------------------------------
# To predict a single Image
>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg

Output is stored in runs/detect folder

To remove False Positive (Remove B box with low confidence)


>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg conf=0.5

To show output in real time


>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg conf=0.5 show=True

To save b box info


>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg conf=0.5
save_txt=True
Note: Labels are stored with bounding box in runs folder

To save cropped object


>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg conf=0.5
save_txt=True save_crop=True
Note: Cropped are stored with bounding box in runs/detect/crops folder

To remove confidence and label


>> yolo task=detect mode=predict model=YOLO8n.pt source=1.jpg conf=0.5
save_crop=True hide_labels=True hide_conf=true

To test on custom video and output in real time


>> yolo task=detect mode=predict model=YOLO8n.pt source=video.mp4 conf=0.5
show=True
Output is stored in hard drive --False positive>> Change Model

To test on webcam and output in real time


>> yolo task=detect mode=predict model=YOLO8n.pt source=0 conf=0.5 show=True
Output is stored in hard drive --False positive>> Change Model
To test on IP webcam and output in real time
>> yolo task=detect mode=predict model=YOLO8n.pt source="URL" conf=0.5 show=True
Output is stored in hard drive --False positive>> Change Model

To test on custom test dataset


>> yolo task=detect mode=predict model=YOLO8n.pt source=testDirectory conf=0.5
show=True
Output is stored in hard drive --False positive>> Change Model

-------------------------For image Segmentation -- Look for segment in GITHUB


repository---------

>> yolo task=segment mode=predict model=YOLO8n-seg.pt source=1.jpeg conf=0.5


hide_labels=True hide_conf=true

Output is in run/segment/folder

To save Polygon info


>> yolo task=segment mode=predict model=YOLO8n-seg.pt source=1.jpeg conf=0.5
save_txt=True hide_labels=True hide_conf=true
Note: Text file with polygon are stored with bounding box in runs folder

To run on video
>> yolo task=segment mode=predict model=YOLO8n-seg.pt source="Video.mp4 conf=0.5
show=True

Output stored in Hard drive

------------------------------For Image
Classification----------------------------------

To classify Go to GITHUB and see classification model weights (model=YOLO8n-cls.pt)

# To train
>> yolo task=classify mode=train model=YOLO8n-cls.pt data=path epochs=1 imgsz=224

TO EXPORT MODEL
> yolo mode=export task=predict model=YOLO8n.pt format=onxx
> yolo mode=export task=segment model=YOLO8n-seg.pt format=onxx
> yolo mode=export task=classify model=YOLO8n-cls.pt format=onxx

-------------To do in Python----------------------------

from ultralytics import YOLO


model=YOLO("yolov8x-cls.pt")
path="C:\Research\Major Project\CVIP2023 Challenge\WCEBleedGen\Classification\
Dataset"
if __name__ == '__main__':
# Use the model
#results = model.train(data="C:/Research\Major Project/CVIP2023
Challenge/WCEBleedGen/Classification/Dataset/custom_data.yaml",imgsz=224,epochs=10)
# train the model
results = model.train(data=path, epochs=100, imgsz=224)

#results = model.val() # evaluate model performance on the validation set


#results = model("https://ultralytics.com/images/bus.jpg") # predict on an
image

--------------Predict.py---------------------------

from ultralytics import YOLO


model=YOLO("yolov8m.pt)
model.predict(source="1.jpeg",save=True,conf=0.5,save_txt=True)
model.export(format="onxx"
>> python predict.py

--------------Segment.py---------------------------

from ultralytics import YOLO


model=YOLO("yolov8m-seg.pt)
model.predict(source="1.jpeg",save=True,conf=0.5,save_txt=True,show=True)
model.export(format="onxx"
>> python Segment.py.py

--------------Classification.py---------------------------

from ultralytics import YOLO


model=YOLO("yolov8m-cls.pt)
model.predict(source="1.jpeg",save=True,conf=0.5,save_txt=True,show=True)
model.export(format="onxx"
>> python Classification.py

You might also like