-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_yolov8.py
More file actions
42 lines (36 loc) · 992 Bytes
/
train_yolov8.py
File metadata and controls
42 lines (36 loc) · 992 Bytes
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
from ultralytics import YOLO
import torch
def main():
# -----------------------------
# Configuration
# -----------------------------
DATA_YAML = "data/dataset.yaml"
MODEL_NAME = "yolov8n.pt" # start small
EPOCHS = 30
IMG_SIZE = 640
BATCH_SIZE = 16
DEVICE = 0 if torch.cuda.is_available() else "cpu"
RUN_NAME = "mot17_yolov8n"
# -----------------------------
# Load Pretrained Model
# -----------------------------
model = YOLO(MODEL_NAME)
# -----------------------------
# Train
# -----------------------------
model.train(
data=DATA_YAML,
epochs=EPOCHS,
imgsz=IMG_SIZE,
batch=BATCH_SIZE,
device=DEVICE,
workers=8,
name=RUN_NAME,
pretrained=True,
verbose=True,
)
print("\nTraining completed successfully")
print("Best model saved at:")
print(f"runs/detect/{RUN_NAME}/weights/best.pt")
if __name__ == "__main__":
main()