From b5a0d5f1f336f8923986b69ac6721d330acc2578 Mon Sep 17 00:00:00 2001 From: wonder Date: Wed, 5 Nov 2025 19:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=94=84Update:=20[Lab-4]=20yolov8n=20Tr?= =?UTF-8?q?ain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- Lab-4/src/__init__.py | 0 Lab-4/src/train.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 Lab-4/src/__init__.py create mode 100644 Lab-4/src/train.py diff --git a/.gitignore b/.gitignore index 8546bca..fff35e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .idea */img */data -model \ No newline at end of file +model +runs +datasets +yolov8n.pt \ No newline at end of file diff --git a/Lab-4/src/__init__.py b/Lab-4/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Lab-4/src/train.py b/Lab-4/src/train.py new file mode 100644 index 0000000..0f45616 --- /dev/null +++ b/Lab-4/src/train.py @@ -0,0 +1,15 @@ +from ultralytics import YOLO + +# 1. 加载一个预训练模型(小规模模型,适合实验) +# 可选模型: YOLOv8n, YOLOv8s, YOLOv8m, YOLOv8l, YOLOv8x (nano, small, medium, large, xlarge) +model = YOLO('yolov8n.pt') + +# 2. 训练模型 +results = model.train( + data='coco128.yaml', # 数据集配置文件,YOLOv8会自动识别并下载 + epochs=50, # 训练轮次,建议50-100轮以观察效果 + imgsz=640, # 输入图像大小 + batch=16, # 批次大小,根据GPU内存调整(CPU可设为-1) + name='yolov8n_coco128_exp1', # 实验名称,用于保存结果 + device='cpu' # 使用CPU训练,如果有GPU且环境配置好,可改为 device=0 或 'cuda' +)