YOLOV7开源代码讲解--训练参数解释

 

目录

训练参数说明:

--weights:

-- cfg:

--data:

--hpy:

--epoch:

--batch_size:

--img-size:

--rect:

--resume:

--nosave:

--notest:

--noautoanchor:

--evolve:

--bucket:

--cach-images:

--image-weights:

--device:

--multi-scale:

--single-cls:

--adam:

--sync-bn:

--local_rank:

--workers:

--project:

--name:

--exist-ok:

--linear-lr:

--label-smoothing:

--upload_dataset:

--bbox_interval:

--save_period:


训练参数说明:

--weights:

预权重路径,如果设置为--weights=="",则重头训练

-- cfg:

训练中模型的参数定义,采用yaml文件【注意是training下的yaml,不是deploy下的】,可以用于模型的选择

`-- training
    |-- yolov7-d6.yaml
    |-- yolov7-e6.yaml
    |-- yolov7-e6e.yaml
    |-- yolov7-tiny.yaml
    |-- yolov7-w6.yaml
    |-- yolov7.yaml
    `-- yolov7x.yaml
 

--data:

数据集路径,默认为coco.yaml,主要定义数据集路径,以txt文件保存【训练集、验证集和测试集】,类的数量【默认nc=80】,类名【names】。如下:

# COCO 2017 dataset http://cocodataset.org

# download command/URL (optional)
download: bash ./scripts/get_coco.sh

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ./coco/train2017.txt  # 118287 images
val: ./coco/val2017.txt  # 5000 images
test: ./coco/test-dev2017.txt  # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# number of classes
nc: 80

# class names
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]
 

--hpy:

训练中超参数配置路径,默认data/hpy.scratch.p5.yaml,比如学习率、动量参数、权重衰减、预热epoch等。

--epoch:

训练多少轮,默认300轮

--batch_size:

batch大小

--img-size:

输入网络图像大小,默认640 * 640

--rect:

rectangular training(就是不失真的resize图像训练)

--resume:

重新开始最近的训练。用于设置是否在最近训练的一个模型基础上继续训练。默认为False,如果想要开启该功能,需要指定模型路径。

--nosave:

设置为True后只保存最后一个epoch权重

--notest:

设置为True后只测试最后一个epoch

--noautoanchor:

设置为True,表示不自动聚类anchor

--evolve:

设置为True,超参数优化,可以选择自己的更有的超参数(但资源消耗也很厉害),一般情况下用不到

--bucket:

谷歌云盘bucket,一般也用不到

--cach-images:

设置为True,提前缓存图像可用于加速训练

--image-weights:

加权图像选择进行训练。指对于那些训练不理想的图像,再下一次训练的时会增加一些权重,使其更关注这些困难样本

--device:

设备选择,如果是GPU就输入GPU索引【如0,1,2..】,CPU训练就填cpu

--multi-scale:

默认为False,是否采用多尺度训练

--single-cls:

数据集是单类别还是多类别,默认False

--adam:

adam优化器,默认False(即采用随机梯度下降SGD)

--sync-bn:

是否使用跨卡同步BN,在DDP模式使用,默认False

--local_rank:

DDP参数(不要改动)

--workers:

线程数,根据自己的电脑设置

--project:

训练模型保存的位置,默认为run/train

--name:

保存项目名字,一般是run/train/exp

--exist-ok:

模型目录是否存在,不存在就创建

--linear-lr:

对于学习率的调整,默认为False,开启后用余弦函数调整学习率

--label-smoothing:

标签平滑,防止过拟合

--upload_dataset:

更新数据集,和wandb 库有关。也基本不用

--bbox_interval:

设置bbox log,也是和wandb有关,一般用不到

--save_period:

在每个保存周期的epoch后用于记录模型日志,默认为-1


  
  
  1. if __name__ == '__main__':
  2. parser = argparse.ArgumentParser()
  3. parser.add_argument( '--weights', type= str, default= 'yolov7.pt', help= 'initial weights path')
  4. parser.add_argument( '--cfg', type= str, default= 'cfg/training/yolov7.yaml', help= 'model.yaml path')
  5. parser.add_argument( '--data', type= str, default= 'data/mydata.yaml', help= 'data.yaml path')
  6. parser.add_argument( '--hyp', type= str, default= 'data/hyp.scratch.p5.yaml', help= 'hyperparameters path')
  7. parser.add_argument( '--epochs', type= int, default= 300)
  8. parser.add_argument( '--batch-size', type= int, default= 2, help= 'total batch size for all GPUs')
  9. parser.add_argument( '--img-size', nargs= '+', type= int, default=[ 640, 640], help= '[train, test] image sizes')
  10. parser.add_argument( '--rect', action= 'store_true', help= 'rectangular training')
  11. # resume是重新开始最近的训练
  12. parser.add_argument( '--resume', nargs= '?', const= True, default= False, help= 'resume most recent training')
  13. parser.add_argument( '--nosave', action= 'store_true', help= 'only save final checkpoint')
  14. parser.add_argument( '--notest', action= 'store_true', help= 'only test final epoch')
  15. parser.add_argument( '--noautoanchor', action= 'store_true', help= 'disable autoanchor check')
  16. parser.add_argument( '--evolve', action= 'store_true', help= 'evolve hyperparameters')
  17. parser.add_argument( '--bucket', type= str, default= '', help= 'gsutil bucket')
  18. parser.add_argument( '--cache-images', action= 'store_true', help= 'cache images for faster training')
  19. parser.add_argument( '--image-weights', action= 'store_true', help= 'use weighted image selection for training')
  20. parser.add_argument( '--device', default= '', help= 'cuda device, i.e. 0 or 0,1,2,3 or cpu')
  21. parser.add_argument( '--multi-scale', action= 'store_true', help= 'vary img-size +/- 50%%')
  22. parser.add_argument( '--single-cls', action= 'store_true', help= 'train multi-class data as single-class')
  23. parser.add_argument( '--adam', action= 'store_true', help= 'use torch.optim.Adam() optimizer')
  24. parser.add_argument( '--sync-bn', action= 'store_true', help= 'use SyncBatchNorm, only available in DDP mode')
  25. parser.add_argument( '--local_rank', type= int, default=- 1, help= 'DDP parameter, do not modify')
  26. parser.add_argument( '--workers', type= int, default= 4, help= 'maximum number of dataloader workers')
  27. parser.add_argument( '--project', default= 'runs/train', help= 'save to project/name')
  28. parser.add_argument( '--entity', default= None, help= 'W&B entity')
  29. parser.add_argument( '--name', default= 'exp', help= 'save to project/name')
  30. parser.add_argument( '--exist-ok', action= 'store_true', help= 'existing project/name ok, do not increment')
  31. parser.add_argument( '--quad', action= 'store_true', help= 'quad dataloader')
  32. parser.add_argument( '--linear-lr', action= 'store_true', help= 'linear LR')
  33. parser.add_argument( '--label-smoothing', type= float, default= 0.0, help= 'Label smoothing epsilon')
  34. parser.add_argument( '--upload_dataset', action= 'store_true', help= 'Upload dataset as W&B artifact table')
  35. parser.add_argument( '--bbox_interval', type= int, default=- 1, help= 'Set bounding-box image logging interval for W&B')
  36. parser.add_argument( '--save_period', type= int, default=- 1, help= 'Log model after every "save_period" epoch')
  37. parser.add_argument( '--artifact_alias', type= str, default= "latest", help= 'version of dataset artifact to be used')
  38. opt = parser.parse_args()

 wandb库的使用可以参考以下链接,该库是一个类似于tensorboard的工具。

wandb使用方法以及具体设置_神晟的光辉的博客-CSDN博客_wandb使用教程

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Yolov7是一种目标检测算法,它是由ultralytics发的一种新型算法,是YOLOv5的改进版本。Yolov7算法相比于其前身YOLOv5有更好的性能,同时也提供了更加便利的可视化和调试功能。 Yolov7的核心思想是通过一个单一的神经网络模型,在图像中同时检测出多个目标,这个模型可以在GPU上快速地运行。而Yolov7相对于YOLOv5的改进之处主要在于模型架构上的优化,包括使用了更多的卷积和更少的池化层,以及采用了更加高效的模型设计和训练方法。 下面对Yolov7源代码进行简单的讲解: 1. 首先,你需要下载Yolov7源代码,可以从GitHub上找到ultralytics的Yolov7仓库:https://github.com/ultralytics/yolov7 2. 在下载完成后,你需要安装相关的依赖库,其中包括pytorch、opencv和matplotlib等。 3. 接着,你可以通过运行train.py来进行模型训练。train.py中包括了训练模型所需的各种参数配置,包括数据集路径、batch size、学习率等等。通过修改这些参数,你可以对模型的训练过程进行调整。 4. 训练完成后,你可以通过运行detect.py来对图像或视频进行目标检测。detect.py中包括了目标检测所需的各种参数配置,包括模型权重、检测阈值、NMS阈值等等。通过修改这些参数,你可以对目标检测的结果进行调整。 5. 最后,Yolov7还提供了一些可视化和调试工具,包括展示训练过程中的loss曲线、绘制目标检测结果等等。 总之,Yolov7是一种高效的目标检测算法,其源代码提供了完整的训练和测试流程,可以方便地应用于实际项目中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值