# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/] train: ../VOC/images/train/ # 16551 images val: ../VOC/images/val/ # 4952 images # number of classes nc: 20 # class names names: [ 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor' ] 12345678910 1.2 数据增强策略 multi-scale resize 训练的时候对原始图像进行随机尺寸变换默认关闭通过命令行参数 --multi-scale 开启 mosaic 模型训练输入图片是由4张原始图片拼接而成根据比例使用,比例是由超参数配置文件(即 --hyp 指定的配置文件)中的 mosaic 指定。两个默认的 --hyp 中mosaic默认比例是100%,即轮训练都使用。 mixup 两张图片逐像素叠加,label根据透明度叠加。根据比例使用,比例是由超参数配置文件(即 --hyp 指定的配置文件)中的 mixup 指定。 random_perspective 如果没有使用 mosaic 就对原始图像使用该增强。mosaic 数据曾庆方式中也有使用该方法对结果进行小变换增强方式就是一些像素级的数字图像变换,如旋转、平移、扭曲等。 augment_hsv 图像色彩变换,亮度、饱和度、对比度啥的。默认开启。 翻转 包括水平翻转与垂直翻转根据比例使用,比例是由超参数配置文件(即 --hyp 指定的配置文件)中的 flipud/fliplr 指定。
python train.py --cfg /path/to/yolov5s.yaml --data /path/to/data.yaml 1
其他可选参数还有很多,自己看配置原文件吧。
有几个参数看不懂是什么意思,没关系,看不懂的就是不常用的,放着也没事。单机多卡命令如下
我只放了自己关心的,方便以后自己复制粘贴--project 和 --name 非常好用,过程文件与权重文件都会放在 {project}/{name} 当中。python train.py --device 4,5,6,7 --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --data data/coco.yaml --hyp data/hyp.scratch.yaml --epochs 300 --batch-size 128 --img-size 640 --project runs/train --name exp 1234567891011 多卡训练命令如下 比官方教程多了 --master_port 选项,如果服务器上训练多个yolov5模型,如果没有改变端口号就会包括,说 address already in use 一类的。
python -m torch.distributed.launch --nproc_per_node 4 --master_port 23232 train.py --device 4,5,6,7 --weights weights/yolov5s.pt --cfg models/yolov5s.yaml --data data/coco.yaml --hyp data/hyp.scratch.yaml --epochs 300 --batch-size 128 --img-size 640 --project runs/train --name exp 123456789101112 2.2 超参数解析 训练时会指定 --hyp 参数,即超参数配置文件。默认有两个配置文件: data/hyp.scratch.yamldata/hyp.finetune.yaml 那超参数配置文件中,都配置了一些啥呢
# 优化器相关 lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) momentum: 0.937 # SGD momentum/Adam beta1 weight_decay: 0.0005 # optimizer weight decay 5e-4 # Warmup 相关 warmup_epochs: 3.0 # warmup epochs (fractions ok) warmup_momentum: 0.8 # warmup initial momentum warmup_bias_lr: 0.1 # warmup initial bias lr # 不同损失函数权重,以及其他损失函数相关内容 box: 0.05 # box loss gain cls: 0.5 # cls loss gain cls_pw: 1.0 # cls BCELoss positive_weight obj: 1.0 # obj loss gain (scale with pixels) obj_pw: 1.0 # obj BCELoss positive_weight iou_t: 0.20 # IoU training threshold fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) # anchor anchor_t: 4.0 # anchor-multiple threshold # anchors: 3 # anchors per output layer (0 to ignore) # 数据增强相关 - 色彩转换 hsv_h: 0.015 # image HSV-Hue augmentation (fraction) hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) hsv_v: 0.4 # image HSV-Value augmentation (fraction) # 数据增强相关:旋转、平移、扭曲等 degrees: 0.0 # image rotation (+/- deg) translate: 0.1 # image translation (+/- fraction) scale: 0.5 # image scale (+/- gain) shear: 0.0 # image shear (+/- deg) perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 # 数据增强相关 - 翻转 flipud: 0.0 # image flip up-down (probability) fliplr: 0.5 # image flip left-right (probability) # 数据增强相关 - mosaic/mixup mosaic: 1.0 # image mosaic (probability) mixup: 0.0 # image mixup (probability)
12345678910111213141516171819202122232425262728293031323334353637383940414243 2.2 训练过程与结果解析训练过程中输出了很多内容,文件、命令行输出等等。
result.txt 文件解析:共15列,内容分别是
{cur_epoch}/{total_epoch}显存4个训练集损失函数,顺序是 ‘box’, ‘obj’, ‘cls’, ‘total’训练集 bbox 数量图像尺寸(长边尺寸)验证集相关(7项): 平均 precision平均 recallAP@0.5AP@0.5:0.953个损失函数,顺序是 box, obj, cls训练集图像:train_batch0.jpg 等
权重包括在 weights 中,有最后epoch权重以及最优结果权重。
命令行信息:
# 训练过程中的已经非常清晰了,毕竟也输出了每一列的含义 # epoch 训练多少轮,显存占了多少,四类损失函数的数值,bbox的数量,图像长边尺寸 Epoch gpu_mem box obj cls total labels img_size 23/299 8.73G 0.04529 0.05286 0.002293 0.1004 307 640: 0%|▏ | 1/531 [00:06<59:48, 6.77s/it] # 验证集的结果也比较明确 # P 是 mean precision,R 是 mean Recall,两个mAP就不用解释了 Class Images Labels P R mAP@.5 mAP@.5:.95: 100%|██████████████████████████████████████████████████████████████████████████| 17/17 [00:14<00:00, 1.20it/s] all 1031 8245 0.426 0.382 0.338 0.183 123456789
相关知识
YOLOv5 实现目标检测(训练自己的数据集实现猫猫识别)
教程:超详细从零开始yolov5模型训练
(转载)YOLOv5 实现目标检测(训练自己的数据集实现猫猫识别)
YOLOv5集群式训练故障排除指南:常见问题与解决方案,快速解决训练难题
YOLOv5实现目标检测:从零到一训练猫猫识别
模式识别:动物目标检测——YOLOv5开发
蓝黄金刚鹦鹉训练展翅过程记录。
基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的鸟类识别系统(Python+PySide6界面+训练代码)
宠物训练报告记录宠物训练过程和成果并进行分析评估
狗狗训练从零开始阅读记录.docx
网址: Yolov5 (1) 训练过程记录与解析 https://m.mcbbbk.com/newsview294040.html
上一篇: yolov8模型训练结果分析以及 |
下一篇: 【YOLOv8训练结果评估】YO |