YOLOV7 open source code explanation--training parameter explanation

 

Table of contents

Description of training parameters:

--weights:

-- cfg:

--data:

--hpy:

--epoch:

--batch_size:

--img-size:

--rect:

--resume:

--nosave:

--note:

--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:


Description of training parameters:

--weights:

Pre-weight path, if set to --weights=="", retrain

-- cfg:

The parameter definition of the model during training uses the yaml file [note that it is the yaml under training, not the one under deploy], which can be used for model selection

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

--data:

Data set path, the default is coco.yaml, mainly defines the data set path, save [training set, verification set and test set] in txt file, the number of classes [default nc=80], class name [names]. as follows:

# 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:

Hyperparameter configuration path during training, default data/hpy.scratch.p5.yaml, such as learning rate, momentum parameters, weight decay, warm-up epoch, etc.

--epoch:

How many rounds to train, the default is 300 rounds

--batch_size:

batch size

--img-size:

Input network image size, default 640 * 640

--rect:

Rectangular training (that is, undistorted resize image training)

--resume:

Restart the most recent training session. Used to set whether to continue training based on the most recently trained model . The default is False. If you want to enable this function, you need to specify the model path.

--nosave:

When set to True, only the last epoch weights are saved

--note:

Only test the last epoch when set to True

--noautoanchor:

Set to True, indicating that the anchor is not automatically clustered

--evolve:

Set to True, hyperparameter optimization, you can choose your own more hyperparameters (but resource consumption is also very powerful), generally not used

--bucket:

Google Cloud Disk bucket is generally not used

--cach-images:

Set to True, caching images ahead of time can be used to speed up training

--image-weights:

Weighted image selection for training. It means that for those images that are not ideal for training, some weights will be added in the next training to make them pay more attention to these difficult samples

--device:

Device selection, if it is a GPU, enter the GPU index [such as 0, 1, 2..], and fill in cpu for CPU training

--multi-scale:

The default is False, whether to use multi-scale training

--single-cls:

Whether the dataset is single-class or multi-class, the default is False

--adam:

Adam optimizer, the default is False (that is, using stochastic gradient descent SGD)

--sync-bn:

Whether to use cross-card synchronization BN, used in DDP mode, default False

--local_rank:

DDP parameters (do not change)

--workers:

The number of threads, set according to your own computer

--project:

The location where the training model is saved, the default is run/train

--name:

Save the project name, usually run/train/exp

--exist-ok:

Whether the model directory exists, create it if it does not exist

--linear-lr:

For the adjustment of the learning rate, the default is False, and the cosine function is used to adjust the learning rate after it is turned on

--label-smoothing:

Label smoothing to prevent overfitting

--upload_dataset:

Updating the dataset is related to the wandb library. basically no need

--bbox_interval:

Setting the bbox log is also related to wandb, which is generally not used

--save_period:

Used to record the model log after each epoch of the save cycle, the default is -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()

 The use of the wandb library can refer to the following link, which is a tool similar to tensorboard.

How to use wandb and specific settings_Shensheng's brilliant blog-CSDN blog_wandb tutorial

Guess you like

Origin blog.csdn.net/z240626191s/article/details/126500617