-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample Practice Code-Experiment-YoloV10-Model.py
124 lines (76 loc) · 3.64 KB
/
Sample Practice Code-Experiment-YoloV10-Model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Sample Practice Code-Experiment-YoloV10-Model
Automatically generated by Google Colab.
Import Basic Librarries:-
"""
import os
!nvidia-smi
HOME = os.getcwd()
print(HOME)
!pip install ultralytics==8.0.196
from IPython import display
display.clear_output()
import ultralytics
ultralytics.checks()
from ultralytics import YOLO
from IPython.display import display, Image
"""Related Works:-"""
#https://youtu.be/neBZ6huolkg
#https://youtu.be/wuZtUMEiKWY
#https://youtu.be/Dmv4EVBuCTQ
# Commented out IPython magic to ensure Python compatibility.
!mkdir {HOME}/datasets
# %cd {HOME}/datasets
!pip install roboflow --quiet
"""Custom Training with RoboflowDataset Annotations:- Sample Relavant Data Collections
* https://universe.roboflow.com/sportsfootballdataanalytics/footballsportsdataanalyticsyolov-image-dataset
* https://universe.roboflow.com/azami-youssef/test_project-3cocv/dataset/
Sample Code-Footballsports Data Analytics-YoloV10 models Implementations:-
"""
!pip install -q supervision
!pip install -q git+https://github.com/THU-MIG/yolov10.git
"""Download pre-trained weights:-"""
!mkdir -p {HOME}/weights
!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10n.pt
#!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10s.pt
#!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10m.pt
#!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10b.pt
#!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10x.pt
#!wget -P {HOME}/weights -q https://github.com/jameslahm/yolov10/releases/download/v1.0/yolov10l.pt
!ls -lh {HOME}/weights
"""Download Pre-trained Custom Roboflow Datasets:-"""
from roboflow import Roboflow
rf = Roboflow(api_key="Cvw2eB4Y45dwuOvsMfsV")
project = rf.workspace("azami-youssef").project("test_project-3cocv") #Data Selection for this experiment
version = project.version(2)
dataset = version.download("yolov8") # yolov4, 5, 8 , 9 based on the requirements.
# Commented out IPython magic to ensure Python compatibility.
# %cd {HOME}
!yolo task=detect mode=train model=/content/weights/yolov10n.pt data={dataset.location}/data.yaml epochs=4 imgsz=1000 plots=True
#%cd {HOME}
#!yolo task=detect mode=train epochs=100 batch=64 plots=True \
#model={HOME}/weights/yolov10x.pt \
#data={dataset.location}/data.yaml
!ls {HOME}/runs/detect/train/
# Commented out IPython magic to ensure Python compatibility.
# %cd {HOME}
Image(filename=f'{HOME}/runs/detect/train/confusion_matrix.png', width=600)
# Commented out IPython magic to ensure Python compatibility.
# %cd {HOME}
Image(filename=f'{HOME}/runs/detect/train/results.png', width=600)
#%cd {HOME}
#Image(filename=f'{HOME}/runs/detect/train/val_batch0_pred.jpg', width=940)
"""Validate Custom Model:-"""
# Commented out IPython magic to ensure Python compatibility.
# %cd {HOME}
!yolo task=detect mode=val model={HOME}/runs/detect/train/weights/best.pt data={dataset.location}/data.yaml
"""Inference with Custom Model:-"""
# Commented out IPython magic to ensure Python compatibility.
# %cd {HOME}
!yolo task=detect mode=predict model={HOME}/runs/detect/train/weights/best.pt conf=0.40 source={dataset.location}/test/images save=True
import glob
from IPython.display import Image, display
for image_path in glob.glob(f'{HOME}/runs/detect/predict/*.jpg')[:4]:
display(Image(filename=image_path, width=640))
print("\n")
"""Inference on Sample Video Datasets;-"""
#!yolo task=detect mode=predict conf=0.30 save=True model=runs/detect/train/weights/best.pt source=/content/Input-Unseen-test.mp4