简体中文 | English
YOLOv4 has not changed much from YOLOv3 at the network structure level. It's just that the backbone network replaced the original Darknet53 by CSPDarknet53, while introducing SPP and PAN ideas for feature fusion of different scales.
Use Netron to visualize the YOLOv4 model structure. Click【here】 for details
yolo_loss_type=yolov5
. For details, please refer to the YOLOv5 chapter. Set to None or yolov4 to use the original YOLO series loss function.Prepare the data set required for training by yourself, and specify the location of the data to be trained. For specific operations, please refer to 【here】for data set preparation. Find the yolov4 configuration file and modify the following parts
data = dict(
batch_size=64, #cumulative batch size, the framework will cumulatively update the gradient after the batch size is accumulated
subdivisions=8, #The number of batches, the actual batch size is batch_size/subdivisions, modify the value size according to your own machine configuration. If the video memory is sufficient, the value can be set smaller, if the video memory is insufficient, the value can be set larger.
workers_per_gpu=2, #dataloader The number of working threads for loading data
train=dict(
type='Custom',
data_root=r'xxxx', #training data root directory
ann_file=r'annotations/train.txt', #Tag file location, relative path. data_root+ann_file
img_prefix='images', #Picture storage path directory, relative path. data_root+img_prefix
name_file='annotations/label.names', #label index corresponding name
pipeline=train_pipeline
),
val=dict(
type='Custom',
data_root=r'xxxx', # Same as above
ann_file=r'annotations/val.txt', # Same as above
img_prefix='images', #same as above
name_file='annotations/label.names', #same as above
pipeline=val_pipeline
),
test=dict(
type='Custom',
data_root=r'xxx', # Same as above
ann_file=r'annotations/test.txt', # Same as above
img_prefix='images', #same as above
name_file='annotations/label.names', #same as above
pipeline=test_pipeline
)
)
python tools/train.py ${CONFIG_FILE}
If you want to specify the working directory in the command, you can add a parameter --work_dir ${YOUR_WORK_DIR}
.
python tools/train.py ${CONFIG_FILE} --device ${device} [optional arguments]
Optional parameters:
--validate
(strongly recommended): every time k during the training epoch (the default value is 1, you can modify this) to execute Evaluation.
--work_dir ${WORK_DIR}
: Overwrite the working directory specified in the configuration file.
--device ${device}
: assign cuda device , 0 or 0,1,2,3 or cpu,use all by default。
--resume_from ${CHECKPOINT_FILE}
: Resume training from the checkpoints file of previous training.
--multi-scale
: Multi-scale scaling, the size range is +/- 50% of the training image size
The difference between resume_from
and load_from
:
resume_from
loads the model weight and optimizer state, and the training continues from the specified checkpoint. It is usually used to resume training that was interrupted unexpectedly.
load_from
only loads model weights, and training starts from epoch 0. It is usually used for fine-tuning.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。