- 安装GPU驱动,cuda
验证安装,nvidia-smi命令查看状态
nvcc -V查看cuda版本, 按安装后提示配置路径。
注意:
cuda选择版本, 对pytorch支持有关系,目前pytorch最高支持到11.8 ,实测A5000装530驱动,安装cuda12.2会无法正确运行,可以降级安装cuda11.8,可以完美匹配。
- 安装pytorch
用conda安装,确保版本兼容
conda install pytorch
验证安装正确,且cuda支持OK,
- 安装python虚拟环境,方便测试
安装配置miniconda
- yolo环境配置
仓库:
GitHub - ultralytics/ultralytics: Ultralytics YOLO11 🚀
官方文档,安装最好用conda方式:
安装过程遇到的错误及排查:
undefined symbol: __nvJitLinkComplete_12_4, version libnvJitLink.so.12
是torch版本匹配问题,降级到cuda11.8
官方有conda安装方式,但是外网限制问题,无法安装,会报错,连接不上conda
conda install -c conda-forge ultralytics
git安装
git目录后用pip安装可以正常使用
pip install -e .
测试python导入环境
命令行测试图片:
yolo predict model=yolo11s.pt source='https://ultralytics.com/images/bus.jpg' imgsz=320
命令行预测(predict)视频:
yolo predict model=yolo11n-seg.pt source=./1.mp4 imgsz=320
验证训练流程:
yolo train data=coco8.yaml model=yolo11n.pt epochs=10 lr0=0.01
训练结果
(py39yolov11) hy@hy-C621-WD12-IPMI:~/yolopan/ultralytics$ yolo train data=coco8.yaml model=yolo 11n.pt epochs=10 lr0=0.01
Ultralytics 8.3.63 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
engine/trainer: task=detect, mode=train, model=yolo11n.pt, data=coco8.yaml, epochs=10, time=Non e, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, work ers=8, project=None, name=train2, exist_ok=False, pretrained=True, optimizer=auto, verbose=True , seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resu me=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=T rue, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=N one, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream _buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=F alse, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=Fal se, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, ker as=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=None, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_ momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, nbs=64, hsv_h =0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0 , flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save _dir=/home/hy/yolopan/ultralytics/runs/detect/train2
from n params module arguments
0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2 ]
1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2]
2 -1 1 6640 ultralytics.nn.modules.block.C3k2 [32, 64, 1, False, 0.25]
3 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
4 -1 1 26080 ultralytics.nn.modules.block.C3k2 [64, 128, 1, False, 0.25]
5 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3 , 2]
6 -1 1 87040 ultralytics.nn.modules.block.C3k2 [128, 128, 1 , True]
7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3 , 2]
8 -1 1 346112 ultralytics.nn.modules.block.C3k2 [256, 256, 1 , True]
9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5 ]
10 -1 1 249728 ultralytics.nn.modules.block.C2PSA [256, 256, 1 ]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'n earest']
12 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1]
13 -1 1 111296 ultralytics.nn.modules.block.C3k2 [384, 128, 1 , False]
14 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'n earest']
15 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1]
16 -1 1 32096 ultralytics.nn.modules.block.C3k2 [256, 64, 1, False]
17 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
18 [-1, 13] 1 0 ultralytics.nn.modules.conv.Concat [1]
19 -1 1 86720 ultralytics.nn.modules.block.C3k2 [192, 128, 1 , False]
20 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3 , 2]
21 [-1, 10] 1 0 ultralytics.nn.modules.conv.Concat [1]
22 -1 1 378880 ultralytics.nn.modules.block.C3k2 [384, 256, 1 , True]
23 [16, 19, 22] 1 464912 ultralytics.nn.modules.head.Detect [80, [64, 12 8, 256]]
YOLO11n summary: 319 layers, 2,624,080 parameters, 2,624,064 gradients, 6.6 GFLOPs
Transferred 499/499 items from pretrained weights
Freezing layer 'model.23.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks...
AMP: checks passed ✅
train: Scanning /home/hy/yolopan/datasets/coco8/labels/train.cache... 4 images, 0 backgrounds,
val: Scanning /home/hy/yolopan/datasets/coco8/labels/val.cache... 4 images, 0 backgrounds, 0 co
Plotting labels to /home/hy/yolopan/ultralytics/runs/detect/train2/labels.jpg...
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'mom entum' automatically...
optimizer: AdamW(lr=0.000119, momentum=0.9) with parameter groups 81 weight(decay=0.0), 88 weight(decay=0.0005), 87 bias(dec ay=0.0)
Image sizes 640 train, 640 val
Using 8 dataloader workers
Logging results to /home/hy/yolopan/ultralytics/runs/detect/train2
Starting training for 10 epochs...
Closing dataloader mosaic
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
1/10 0.692G 1.059 1.862 1.417 13 640: 100%|██████████| 1/1 [00:01<00:00, 1.03s/it]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00,
all 4 17 0.579 0.85 0.878 0.634
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
2/10 0.692G 1.219 2.578 1.548 13 640: 100%|██████████| 1/1 [00:00<00:00, 7.97it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00,
all 4 17 0.582 0.85 0.849 0.631
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
3/10 0.692G 0.9898 1.863 1.466 13 640: 100%|██████████| 1/1 [00:00<00:00, 9.93it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00,
all 4 17 0.6 0.85 0.849 0.648
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
4/10 0.692G 1.12 1.911 1.406 13 640: 100%|██████████| 1/1 [00:00<00:00, 10.29it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00,
all 4 17 0.613 0.85 0.85 0.649
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
5/10 0.69G 0.916 2.056 1.149 13 640: 100%|██████████| 1/1 [00:00<00:00, 6.19it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 25.48it/s]
all 4 17 0.623 0.85 0.851 0.649
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
6/10 0.711G 0.9636 2.127 1.297 13 640: 100%|██████████| 1/1 [00:00<00:00, 9.93it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 23.77it/s]
all 4 17 0.626 0.85 0.853 0.651
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
7/10 0.719G 1.204 2.029 1.541 13 640: 100%|██████████| 1/1 [00:00<00:00, 9.16it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 28.18it/s]
all 4 17 0.624 0.85 0.89 0.64
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
8/10 0.711G 1.163 1.71 1.323 13 640: 100%|██████████| 1/1 [00:00<00:00, 9.21it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 28.27it/s]
all 4 17 0.636 0.85 0.855 0.633
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
9/10 0.719G 1.048 1.896 1.427 13 640: 100%|██████████| 1/1 [00:00<00:00, 8.56it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 26.34it/s]
all 4 17 0.636 0.85 0.855 0.633
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
10/10 0.711G 0.9268 1.613 1.245 13 640: 100%|██████████| 1/1 [00:00<00:00, 7.31it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 26.95it/s]
all 4 17 0.635 0.85 0.858 0.633
10 epochs completed in 0.002 hours.
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/detect/train2/weights/last.pt, 5.5MB
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/detect/train2/weights/best.pt, 5.5MB
Validating /home/hy/yolopan/ultralytics/runs/detect/train2/weights/best.pt...
Ultralytics 8.3.63 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
YOLO11n summary (fused): 238 layers, 2,616,248 parameters, 0 gradients, 6.5 GFLOPs
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 33.59it/s]
all 4 17 0.626 0.85 0.853 0.634
person 3 10 0.614 0.6 0.604 0.281
dog 1 1 0.552 1 0.995 0.796
horse 1 2 0.736 1 0.995 0.675
elephant 1 2 0.388 0.5 0.537 0.261
umbrella 1 1 0.589 1 0.995 0.895
potted plant 1 1 0.877 1 0.995 0.895
Speed: 0.2ms preprocess, 2.3ms inference, 0.0ms loss, 0.8ms postprocess per image
Results saved to /home/hy/yolopan/ultralytics/runs/detect/train2
💡 Learn more at https://docs.ultralytics.com/modes/train
验证OBB测试环境
yolo obb predict model=yolo11n-obb.pt source='https://ultralytics.com/images/boats.jpg'
识别效果:
验证OBB训练数据
支持的数据集包括:
支持的数据集
目前支持以下带有定向边框的数据集:
- DOTA-v1:DOTA 数据集的第一个版本,提供了一套全面的航空图像,并带有用于物体检测的定向边界框。
- DOTA-v1.5:DOTA 数据集的中间版本,与 DOTA-v1 相比提供了更多注释和改进,用于增强物体检测任务。
- DOTA-v2:DOTA(用于航空图像中物体检测的大规模数据集)第 2 版强调从航空角度进行检测,包含 170 万个实例和 11 268 幅图像的定向边界框。
- DOTA8:完整 DOTA 数据集的 8 幅图像子集,适用于测试工作流程和 OBB 培训的持续集成 (CI) 检查。
ultralytics
存放处。
只是测试,可以用dota8跑流程,把数据下载到本地,解压到/path/datasets/
https://ultralytics.com/assets/dota8.zip
也可以先把obb模型下载,
https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-obb.pt
用rolabelimg标注的数据集是
训练命令:
yolo obb train data=dota8.yaml model=yolo11n-obb.pt epochs=10 imgsz=1024
(py39yolov11) hy@hy-C621-WD12-IPMI:~/yolopan/ultralytics$ yolo obb train data=dota8.yaml model=yolo11n-obb.pt epochs=10 imgsz=1024
Ultralytics 8.3.63 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
engine/trainer: task=obb, mode=train, model=yolo11n-obb.pt, data=dota8.yaml, epochs=10, time=None, patience=100, batch=16, imgsz=1024, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train3, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=None, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=/home/hy/yolopan/ultralytics/runs/obb/train3
Overriding model.yaml nc=80 with nc=15
from n params module arguments
0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2]
2 -1 1 6640 ultralytics.nn.modules.block.C3k2 [32, 64, 1, False, 0.25]
3 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
4 -1 1 26080 ultralytics.nn.modules.block.C3k2 [64, 128, 1, False, 0.25]
5 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2]
6 -1 1 87040 ultralytics.nn.modules.block.C3k2 [128, 128, 1, True]
7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2]
8 -1 1 346112 ultralytics.nn.modules.block.C3k2 [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5]
10 -1 1 249728 ultralytics.nn.modules.block.C2PSA [256, 256, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1]
13 -1 1 111296 ultralytics.nn.modules.block.C3k2 [384, 128, 1, False]
14 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
15 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1]
16 -1 1 32096 ultralytics.nn.modules.block.C3k2 [256, 64, 1, False]
17 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
18 [-1, 13] 1 0 ultralytics.nn.modules.conv.Concat [1]
19 -1 1 86720 ultralytics.nn.modules.block.C3k2 [192, 128, 1, False]
20 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2]
21 [-1, 10] 1 0 ultralytics.nn.modules.conv.Concat [1]
22 -1 1 378880 ultralytics.nn.modules.block.C3k2 [384, 256, 1, True]
23 [16, 19, 22] 1 505264 ultralytics.nn.modules.head.OBB [15, 1, [64, 128, 256]]
YOLO11n-obb summary: 344 layers, 2,664,432 parameters, 2,664,416 gradients, 6.7 GFLOPs
Transferred 541/541 items from pretrained weights
Freezing layer 'model.23.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks...
AMP: checks passed ✅
train: Scanning /home/hy/yolopan/datasets/dota8/labels/train... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 52
train: New cache created: /home/hy/yolopan/datasets/dota8/labels/train.cache
val: Scanning /home/hy/yolopan/datasets/dota8/labels/val... 4 images, 0 backgrounds, 0 corrupt: 100%|██████████| 4/4 [00:00<00:00, 625.25
val: New cache created: /home/hy/yolopan/datasets/dota8/labels/val.cache
Plotting labels to /home/hy/yolopan/ultralytics/runs/obb/train3/labels.jpg...
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically...
optimizer: AdamW(lr=0.000526, momentum=0.9) with parameter groups 87 weight(decay=0.0), 97 weight(decay=0.0005), 96 bias(decay=0.0)
Image sizes 1024 train, 1024 val
Using 8 dataloader workers
Logging results to /home/hy/yolopan/ultralytics/runs/obb/train3
Starting training for 10 epochs...
Closing dataloader mosaic
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
1/10 1.62G 0.7865 0.4889 1.274 125 1024: 100%|██████████| 1/1 [00:01<00:00, 1.34s/it]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 4.45it/s]
all 4 8 0.944 1 0.995 0.804
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
2/10 1.67G 0.8854 0.4443 1.459 112 1024: 100%|██████████| 1/1 [00:00<00:00, 4.53it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 14.57it/s]
all 4 8 0.942 1 0.995 0.804
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
3/10 1.68G 0.7773 0.4294 1.505 80 1024: 100%|██████████| 1/1 [00:00<00:00, 7.89it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 12.67it/s]
all 4 8 0.94 1 0.995 0.804
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
4/10 1.73G 0.7714 0.4289 1.781 106 1024: 100%|██████████| 1/1 [00:00<00:00, 7.32it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 16.88it/s]
all 4 8 0.936 1 0.995 0.804
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
5/10 1.72G 0.8086 0.5075 1.195 122 1024: 100%|██████████| 1/1 [00:00<00:00, 8.05it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 20.90it/s]
all 4 8 0.934 1 0.995 0.804
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
6/10 1.64G 0.7477 0.4211 1.381 112 1024: 100%|██████████| 1/1 [00:00<00:00, 8.29it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 21.25it/s]
all 4 8 0.932 1 0.995 0.797
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
7/10 1.6G 0.7764 0.4645 1.679 90 1024: 100%|██████████| 1/1 [00:00<00:00, 8.51it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 19.87it/s]
all 4 8 0.926 1 0.995 0.797
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
8/10 1.67G 0.8228 0.6261 1.396 125 1024: 100%|██████████| 1/1 [00:00<00:00, 8.60it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 19.98it/s]
all 4 8 0.923 1 0.995 0.797
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
9/10 1.65G 0.7391 0.415 1.557 116 1024: 100%|██████████| 1/1 [00:00<00:00, 7.82it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 19.98it/s]
all 4 8 0.92 1 0.995 0.797
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
10/10 1.67G 0.7673 0.5214 1.182 121 1024: 100%|██████████| 1/1 [00:00<00:00, 7.47it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 19.88it/s]
all 4 8 0.911 1 0.995 0.797
10 epochs completed in 0.002 hours.
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/obb/train3/weights/last.pt, 5.9MB
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/obb/train3/weights/best.pt, 5.9MB
Validating /home/hy/yolopan/ultralytics/runs/obb/train3/weights/best.pt...
Ultralytics 8.3.63 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
YOLO11n-obb summary (fused): 257 layers, 2,656,648 parameters, 0 gradients, 6.6 GFLOPs
Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 1/1 [00:00<00:00, 25.32it/s]
all 4 8 0.933 1 0.995 0.797
baseball diamond 3 4 0.879 1 0.995 0.828
basketball court 1 3 0.958 1 0.995 0.866
soccer ball field 1 1 0.962 1 0.995 0.697
Speed: 0.4ms preprocess, 2.4ms inference, 0.0ms loss, 1.7ms postprocess per image
Results saved to /home/hy/yolopan/ultralytics/runs/obb/train3
💡 Learn more at https://docs.ultralytics.com/modes/train
速度还行。
整理自己的数据集,用来训练光伏的带方向框检测;
标注数据(带倾斜框,数据格式?)
用rolabelimg标注数据为xml格式,需要转换成txt格式,才能调用类似dota8的格式训练;
lableme标注的是json格式,都需要转换。
先转换xml为dota的txt格式,然后用yolo自带的脚本再转换成yolo-obb的txt格式:
import sys
sys.path.append('/home/code/wll/code/ultralytics-main-OBB/ultralytics')
from ultralytics.data.converter import convert_dota_to_yolo_obb
convert_dota_to_yolo_obb('/home/code/wll/code/ultralytics-main-OBB/myData')
执行数据集:
>>> from ultralytics.data.converter import convert_dota_to_yolo_obb
>>> convert_dota_to_yolo_obb('../my_obb_datasets')
Processing train images: 100%|██████████| 16/16 [00:00<00:00, 102456.28it/s]
Processing val images: 100%|██████████| 6/6 [00:00<00:00, 70492.50it/s]
数据集格式必须参照:
- DOTA
├─ images
│ ├─ train
│ └─ val
└─ labels
├─ train_original
└─ val_original
After execution, the function will organize the labels into:
- DOTA
└─ labels
├─ train
└─ val
注意converter代码必须修改两处:
一是classname的列表,另外就是文件类型;
class_mapping = {
"module_front":0,
"module_back":1
# "plane": 0,
# "ship": 1,
# "storage-tank": 2,
# "baseball-diamond": 3,
# "tennis-court": 4,
# "basketball-court": 5,
# "ground-track-field": 6,
# "harbor": 7,
# "bridge": 8,
# "large-vehicle": 9,
# "small-vehicle": 10,
# "helicopter": 11,
# "roundabout": 12,
# "soccer-ball-field": 13,
# "swimming-pool": 14,
# "container-crane": 15,
# "airport": 16,
# "helipad": 17,
}
def convert_label(image_name, image_width, image_height, orig_label_dir, save_dir):
"""Converts a single image's DOTA annotation to YOLO OBB format and saves it to a specified directory."""
orig_label_path = orig_label_dir / f"{image_name}.txt"
save_path = save_dir / f"{image_name}.txt"
print("debug",orig_label_dir,save_dir)
with orig_label_path.open("r") as f, save_path.open("w") as g:
lines = f.readlines()
for line in lines:
parts = line.strip().split()
if len(parts) < 9:
continue
class_name = parts[8]
class_idx = class_mapping[class_name]
coords = [float(p) for p in parts[:8]]
normalized_coords = [
coords[i] / image_width if i % 2 == 0 else coords[i] / image_height for i in range(8)
]
formatted_coords = [f"{coord:.6g}" for coord in normalized_coords]
g.write(f"{class_idx} {' '.join(formatted_coords)}\n")
for phase in ["train", "val"]:
image_dir = dota_root_path / "images" / phase
orig_label_dir = dota_root_path / "labels" / f"{phase}_original"
save_dir = dota_root_path / "labels" / phase
save_dir.mkdir(parents=True, exist_ok=True)
print("debug........")
image_paths = list(image_dir.iterdir())
for image_path in TQDM(image_paths, desc=f"Processing {phase} images"):
# if image_path.suffix != ".jpg": # ".png":
# continue
然后就可以启动训练命令了:
(py39yolopannew) hy@hy-C621-WD12-IPMI:~/yolopan/ultralytics$ yolo obb train data=my_obb.yaml mo del=yolo11n-obb.pt epochs=10
Ultralytics 8.3.59 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
engine/trainer: task=obb, mode=train, model=yolo11n-obb.pt, data=my_obb.yaml, epochs=10, time=N one, patience=100, batch=16, imgsz=1024, save=True, save_period=-1, cache=False, device=None, w orkers=8, project=None, name=train6, exist_ok=False, pretrained=True, optimizer=auto, verbose=T rue, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, r esume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mas k=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, con f=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, str eam_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_mask s=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop= False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=No ne, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warm up_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, nbs=64, hs v_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective= 0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=fl ip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, s ave_dir=/home/hy/yolopan/ultralytics/runs/obb/train6
Overriding model.yaml nc=80 with nc=2
from n params module arguments
0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2 ]
1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2]
2 -1 1 6640 ultralytics.nn.modules.block.C3k2 [32, 64, 1, False, 0.25]
3 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
4 -1 1 26080 ultralytics.nn.modules.block.C3k2 [64, 128, 1, False, 0.25]
5 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3 , 2]
6 -1 1 87040 ultralytics.nn.modules.block.C3k2 [128, 128, 1 , True]
7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3 , 2]
8 -1 1 346112 ultralytics.nn.modules.block.C3k2 [256, 256, 1 , True]
9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5 ]
10 -1 1 249728 ultralytics.nn.modules.block.C2PSA [256, 256, 1 ]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'n earest']
12 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1]
13 -1 1 111296 ultralytics.nn.modules.block.C3k2 [384, 128, 1 , False]
14 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'n earest']
15 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1]
16 -1 1 32096 ultralytics.nn.modules.block.C3k2 [256, 64, 1, False]
17 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2]
18 [-1, 13] 1 0 ultralytics.nn.modules.conv.Concat [1]
19 -1 1 86720 ultralytics.nn.modules.block.C3k2 [192, 128, 1 , False]
20 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3 , 2]
21 [-1, 10] 1 0 ultralytics.nn.modules.conv.Concat [1]
22 -1 1 378880 ultralytics.nn.modules.block.C3k2 [384, 256, 1 , True]
23 [16, 19, 22] 1 502729 ultralytics.nn.modules.head.OBB [2, 1, [64, 128, 256]]
YOLO11n-obb summary: 344 layers, 2,661,897 parameters, 2,661,881 gradients, 6.7 GFLOPs
Transferred 535/541 items from pretrained weights
Freezing layer 'model.23.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks...
AMP: checks passed ✅
train: Scanning /home/hy/yolopan/my_obb_datasets/labels/train... 16 images, 0 backgrounds, 0 co
train: New cache created: /home/hy/yolopan/my_obb_datasets/labels/train.cache
val: Scanning /home/hy/yolopan/my_obb_datasets/labels/val... 6 images, 0 backgrounds, 0 corrupt
val: New cache created: /home/hy/yolopan/my_obb_datasets/labels/val.cache
Plotting labels to /home/hy/yolopan/ultralytics/runs/obb/train6/labels.jpg...
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining bes t 'optimizer', 'lr0' and 'momentum' automatically...
optimizer: AdamW(lr=0.001667, momentum=0.9) with parameter groups 87 weight(decay=0.0), 97 weig ht(decay=0.0005), 96 bias(decay=0.0)
Image sizes 1024 train, 1024 val
Using 8 dataloader workers
Logging results to /home/hy/yolopan/ultralytics/runs/obb/train6
Starting training for 10 epochs...
Closing dataloader mosaic
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
1/10 5.8G 2.857 5.118 3.315 123 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00452 0.11 0.00731 0.0021
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
2/10 6.03G 2.661 4.933 3.164 120 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00454 0.11 0.00733 0.0021
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
3/10 6.24G 2.809 5.047 3.239 119 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00492 0.131 0.00655 0.00175
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
4/10 6.24G 2.799 5.143 3.208 123 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00533 0.153 0.00634 0.00129
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
5/10 6.04G 2.733 5.221 3.103 125 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00532 0.153 0.00671 0.00132
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
6/10 5.84G 2.894 5.016 3.415 125 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00577 0.175 0.00682 0.00158
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
7/10 5.84G 2.648 4.816 3.272 123 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00616 0.164 0.00687 0.00143
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
8/10 5.86G 2.949 5.435 3.323 125 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00673 0.186 0.0074 0.00151
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
9/10 5.87G 2.785 4.857 3.223 125 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00586 0.175 0.00542 0.00123
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
10/10 5.87G 2.668 4.629 3.351 125 1024: 100%|██████████|
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00584 0.175 0.00537 0.0012
10 epochs completed in 0.004 hours.
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/obb/train6/weights/last.pt, 5.8MB
Optimizer stripped from /home/hy/yolopan/ultralytics/runs/obb/train6/weights/best.pt, 5.8MB
Validating /home/hy/yolopan/ultralytics/runs/obb/train6/weights/best.pt...
Ultralytics 8.3.59 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
YOLO11n-obb summary (fused): 257 layers, 2,654,113 parameters, 0 gradients, 6.6 GFLOPs
Class Images Instances Box(P R mAP50 mAP50-95): 100%|
all 6 68 0.00455 0.11 0.00698 0.00199
module_front 5 45 0.00659 0.0889 0.0125 0.00352
module_back 2 23 0.00251 0.13 0.00148 0.000463
Speed: 0.2ms preprocess, 2.3ms inference, 0.0ms loss, 35.4ms postprocess per image
Results saved to /home/hy/yolopan/ultralytics/runs/obb/train6
用训练出来的模型验证测试数据集:
(py39yolopannew) hy@hy-C621-WD12-IPMI:~/yolopan/ultralytics$ yolo obb predict model=/home/hy/yolopan/ultralytics/runs/obb/train6/weights/best.pt source='../my_obb_datasets/test/cam2_flv_2.jpg' Ultralytics 8.3.59 🚀 Python-3.9.21 torch-2.5.1+cu124 CUDA:0 (NVIDIA RTX A5000, 24248MiB)
YOLO11n-obb summary (fused): 257 layers, 2,654,113 parameters, 0 gradients, 6.6 GFLOPs
image 1/1 /home/hy/yolopan/ultralytics/../my_obb_datasets/test/cam2_flv_2.jpg: 576x1024 (no detections), 97.4ms
Speed: 8.0ms preprocess, 97.4ms inference, 35.4ms postprocess per image at shape (1, 3, 576, 1024)
Results saved to /home/hy/yolopan/ultralytics/runs/obb/predict3
💡 Learn more at https://docs.ultralytics.com/modes/predict
检查下结果: 训练10次的模型明显不能用;
增加训练次数到1000次;
中间检测到没有优化空间了就会自动停止:
再对测试图片进行检测:
得到的标注结果, 还有改善空间,流程已跑通。
后续工作:
1)嵌入视频监测流程,作为detector调用
2)分析后视频的推流,更便于其他应用调用
3)分析结果呈现