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

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

–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等。

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

–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

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

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

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

Original: https://blog.csdn.net/z240626191s/article/details/126500617
Author: 爱吃肉的鹏
Title: YOLOV7开源代码讲解–训练参数解释

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/785825/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球