首页 > 其他分享 >【YOLO目标检测实战 】3.使用YOLO11训练COCO128数据集

【YOLO目标检测实战 】3.使用YOLO11训练COCO128数据集

时间:2024-11-06 19:42:46浏览次数:2  
标签:YOLO11 yaml COCO128 ultralytics YOLO coco128 scripts images

1 训练YOLO11模型

  1. 准备训练数据
mkdir datasets && cd datasets

wget https://ultralytics.com/assets/coco128.zip

unzip coco128.zip

cd ..
  1. 准备预训练模型
mkdir weights && cd weights

wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt

wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt

cd ..
  1. 准备配置文件
# 准备数据配置文件
mkdir configs && cd configs

# 拷贝模型配置文件
cp path/to/ultralytics-8.3.24/ultralytics/cfg/models/11/yolo11.yaml ./yolo11.yaml

# 拷贝数据配置文件
cp path/to/ultralytics-8.3.24/ultralytics/cfg/datasets/coco128.yaml ./coco128.yaml

# 拷贝下载字体文件(字体文件在资料下载链接中下载)
cp path/to/Arial.ttf ~/.config/Ultralytics

cd ..
  1. 修改数据配置
 vim configs/coco128.yaml
path: path/to/datasets/coco128 # dataset root dir
train: images/train2017 # train images (relative to 'path') 128 images
val: images/train2017 # val images (relative to 'path') 128 images
test: # test images (optional)
  1. 训练YOLO11模型
mkdir scripts && cd scripts

vim scripts/train.py
from ultralytics import YOLO

model = YOLO('configs/yolo11s.yaml').load('weights/yolo11s.pt')

model.train(
    epochs=100,
    batch=8,
    device='0',
    workers=8,
    imgsz=640,
    project='runs',
    amp=False,
    cache='ram',# 'ram', 'disk' or False
    data='configs/coco128.yaml'
)
python scripts/train.py

2 评估YOLO11模型

vim scripts/val.py
from ultralytics import YOLO

model = YOLO('runs/train/weights/best.pt')

metrics = model.val(project='runs')
metrics.box.map
metrics.box.map50
metrics.box.map75
metrics.box.maps
python scripts/val.py

3 YOLO11推理图片

vim scripts/predict.py
from ultralytics import YOLO

model = YOLO('runs/train/weights/best.pt')

results = model(
    source='datasets/coco128/images/train2017',
    imgsz=640,
    conf=0.5,
    save=True,
    save_txt=True,
    project='runs'
)
python scripts/predict.py

资料下载

链接: https://pan.baidu.com/s/1SkTVrOnsjUnPzO2SkQaV2g 提取码: wxqg

欢迎关注

微信公众号:AI创客工厂

QQ群:392979889

标签:YOLO11,yaml,COCO128,ultralytics,YOLO,coco128,scripts,images
From: https://www.cnblogs.com/d442130165/p/18530913

相关文章