首先下载
https://github.com/hukaixuan19970627/yolov5_obbhttps://github.com/hukaixuan19970627/yolov5_obb
下载权重6.0
由于之前装过yolov5,环境基本配置好了。
按照这个教程可以正常安装。
nms_rotated 安装。pytorch版本需要小于1.12. 不然报错。
Dota_devkit安装,swig需要下载swigwin。并配置环境变量。
按照之前的博客配置数据集。生成labeltxt。
设置图片路径,分类数。yolov5obb_demo.yaml 。说不要1分类。添加一个空的。
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./dataset # dataset root dir
train: images #images # train images (relative to 'path')
val: images #images # val images (relative to 'path')
test: images #images # test images (optional)
# Classes
nc: 2 # number of classes
names: ['ok','null'] # class names
# Download script/URL (optional)
# download: https://ultralytics.com/assets/coco128.zip
然后训练。
使用pytorch是1.10版本。超过1.12会报错。
python train.py --weights weights/yolov5n.pt --cfg models/yolov5n.yaml --data data/yolov5obb.yaml --epochs 100 --device 0 --workers 0 --batch 8 --adam --imgsz=1024
训练需要加入 --adam ,自己的数据集不好收敛。
并且修改hyp.finetune_dota.yaml文件。方便收敛。
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
lr0: 0.001
lrf: 0.2
momentum: 0.937
weight_decay: 0.0005
warmup_epochs: 3.0
warmup_momentum: 0.8
warmup_bias_lr: 0.1
box: 0.05
cls: 0.5
cls_pw: 1.0
theta: 0.5
theta_pw: 1.0
obj: 1.0
obj_pw: 1.0
iou_t: 0.2
anchor_t: 4.0
fl_gamma: 0.0
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 180.0
translate: 0.1
scale: 0.25
shear: 0.0
perspective: 0.0
flipud: 0.5
fliplr: 0.5
mosaic: 0.0
mixup: 0.1
copy_paste: 0.0
cls_theta: 180
csl_radius: 2.0
报错就调小batch
--batch 1
可以训练了。
all那行,不能是0。正常20个epoch之内会正常 出数字。
然后推理。
python detect.py --device 0 --source dataset/images/OK_00004.png --weights runs/train/exp13/weights/best.pt --img=1024
yolov5obb旋转框训练demo资源-优快云文库https://download.youkuaiyun.com/download/vokxchh/87803913完整的可以参考。