yolov5系列-[2]-数据标注、参数设置、训练优化

yolov5系列-[2]-数据标注、参数设置、训练优化


1. 数据标注规范

  • 每个类的图像。≥ 建议每类1500张图片
  • 每个类的实例。≥ 建议每个类10000个实例(标记的对象)
  • 图像多样性。必须代表已部署的环境。对于真实世界的使用案例,我们推荐来自不同时间、不同季节、不同天气、不同照明、不同角度、不同来源(在线收集、本地收集、不同相机)的图像。
  • 标签一致性。必须标记所有图像中所有类的所有实例。部分标签将不起作用。
  • 标签准确性。标签必须紧紧围绕每个对象。对象与其边界框之间不应存在空间。任何对象都不应缺少标签。
  • 标签验证。在火车开始时查看train_batch*.jpg,以验证标签是否正确,即参见示例马赛克。
  • 背景图像。背景图像是没有添加到数据集以减少误报(FP)的对象的图像。我们建议大约0-10%的背景图像,以帮助减少FP(COCO有1000张背景图像供参考,占总数的1%)。背景图像不需要标签。

  • Images per class. ≥ 1500 images per class recommended(每个类的图像。≥ 建议每类1500张图片)
  • Instances per class. ≥ 10000 instances (labeled objects) per class recommended(每个类的实例。≥ 建议每个类10000个实例(标记的对象))
  • Image variety. Must be representative of deployed environment. For real-world use cases we recommend images from different times of day, different seasons, different weather, different lighting, different angles, different sources (scraped online, collected locally, different cameras) etc.(图像多样性。必须代表已部署的环境。对于真实世界的使用案例,我们推荐来自不同时间、不同季节、不同天气、不同照明、不同角度、不同来源(在线收集、本地收集、不同相机)的图像。)
  • Label consistency. All instances of all classes in all images must be labelled. Partial labelling will not work.(标签一致性。必须标记所有图像中所有类的所有实例。部分标签将不起作用。)
  • Label accuracy. Labels must closely enclose each object. No space should exist between an object and it’s bounding box. No objects should be missing a label(标签准确性。标签必须紧紧围绕每个对象。对象与其边界框之间不应存在空间。任何对象都不应缺少标签。)
  • Label verification. View train_batch*.jpg on train start to verify your labels appear correct, i.e. see example mosaic…(标签验证。在火车开始时查看train_batch*.jpg,以验证标签是否正确,即参见示例马赛克。)
  • Background images. Background images are images with no objects that are added to a dataset to reduce False Positives (FP). We recommend about 0-10% background images to help reduce FPs (COCO has 1000 background images for reference, 1% of the total). No labels are required for background images.(背景图像。背景图像是没有添加到数据集以减少误报(FP)的对象的图像。我们建议大约0-10%的背景图像,以帮助减少FP(COCO有1000张背景图像供参考,占总数的1%)。背景图像不需要标签。)

2. 训练设置

  • 训练轮次. 开始设置300轮,如果没有发生过拟合,则设置600、1200。
  • 图片尺寸 默认640.如果数据集中大量小对象,它可以从更高分辨率(如–img 1280)的训练中受益。训练和检测应该使用同样的image_size
  • Batch size. 使用硬件允许的最大批量。小批量产生较差的批量标准统计数据,应避免。
  • 超级参数. 默认超参数为hyp.cratch-low.yaml。我们建议您在考虑修改任何超参数之前先使用默认超参数进行训练。更多请参考:Hyperparameter Evolution Tutorial.
  • 超参数进化是一种使用遗传算法(GA)进行优化的超参数优化方法。2022年9月25日更新。

  • Epochs. Start with 300 epochs. If this overfits early then you can reduce epochs. If overfitting does not occur after 300 epochs, train longer, i.e. 600, 1200 etc epochs.
  • Image size. COCO trains at native resolution of --img 640, though due to the high amount of small objects in the dataset it can benefit from training at higher resolutions such as --img 1280. If there are many small objects then custom datasets will benefit from training at native or higher resolution. Best inference results are obtained at the same --img as the training was run at, i.e. if you train at --img 1280 you should also test and detect at --img 1280.
  • Batch size. Use the largest --batch-size that your hardware allows for. Small batch sizes produce poor batchnorm statistics and should be avoided.
  • Hyperparameters. Default hyperparameters are in hyp.scratch-low.yaml. We recommend you train with default hyperparameters first before thinking of modifying any. In general, increasing augmentation hyperparameters will reduce and delay overfitting, allowing for longer trainings and higher final mAP. Reduction in loss component gain hyperparameters like hyp[‘obj’] will help reduce overfitting in those specific loss components. For an automated method of optimizing these hyperparameters, see our Hyperparameter Evolution Tutorial.

3. 数据增强

4. Multi-GPU Training

  • Single GPU
 python train.py  --batch 64 --data coco.yaml --weights yolov5s.pt --device 0
  • Multi-GPU DistributedDataParallel Mode (✅ recommended)
python -m torch.distributed.run --nproc_per_node 2 train.py --batch 64 --data coco.yaml --weights yolov5s.pt --device 0,1

–nproc_per_node指定要使用的GPU数量。在上面的示例中,它是2.–batch是总批大小。它将平均分配给每个GPU。在上面的示例中,它是64/2=32每GPU。

  • 使用多台机器
# On master machine 0
$ python -m torch.distributed.run --nproc_per_node G --nnodes N --node_rank 0 --master_addr "192.168.1.1" --master_port 1234 train.py --batch 64 --data coco.yaml --cfg yolov5s.yaml --weights ''

# On machine R
$ python -m torch.distributed.run --nproc_per_node G --nnodes N --node_rank R --master_addr "192.168.1.1" --master_port 1234 train.py --batch 64 --data coco.yaml --cfg yolov5s.yaml --weights ''

其中“G”是每台机器的GPU数量,“N”是机器数量,“R”是从“0…(N-1)”开始的机器数量。假设我有两台机器,每台机器都有两个GPU,上面的代码是“G=2”、“N=2”和“R=1”。在所有“N”台机器连接之前,培训将不会开始。输出将仅显示在主机上!


参考:YOLOv5 Documentation

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GeekPlusA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值