Spaces:
Sleeping
Sleeping
File size: 1,309 Bytes
908e980 |
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 |
import os.path
import numpy as np
from ultralytics import YOLO
from file_utils import project_dir
print(project_dir())
def train():
"""
Funksiya modelni train qiladi
data uyidagi formatda bo'lish kerak
# - splitted
# - train
# - good
# - problem
# - val
# - good
# - problem
"""
data_joyi = 'traffic_laws/scripts/splitted/'
model = YOLO('yolov8n-cls.pt')
model.train(data=data_joyi, epochs=100, imgsz=224, batch=512, save_period=10, device='cuda:0', augment=True)
metrics = model.val()
print(metrics.top1) # top1 aniqligi
def tekshirish():
"""
test qilish, model va rasmni berishimiz kerak
"""
train_qilingan_model_joyi = os.path.join(
project_dir(),
"models",
"classification",
"tl-14",
"weights/best.pt"
)
test_rasm_joyi = os.path.join(
project_dir(),
"scripts",
"splitted",
"val",
"good",
"frame_000000_vid_39_1284-2_34good.jpg"
)
model_custom = YOLO(train_qilingan_model_joyi)
natijalar = model_custom(test_rasm_joyi) # predict on an image
natija = natijalar[0].names[np.argmax(natijalar[0].probs.cpu().numpy())]
print(f"Label natija: {natija}")
tekshirish() |