Skip to content

Latest commit

 

History

History
82 lines (57 loc) · 2.84 KB

GETTING_STARTED_cn.md

File metadata and controls

82 lines (57 loc) · 2.84 KB

简体中文 | English

开始

这个页面提供了关于YOLODetection使用的基本教程。

有关安装说明,请参阅INSTALL.md

模型训练

YOLODetection提供执行单卡多卡的训练。 所有输出(日志文件和检查点)将保存到工作目录中。

这是由配置文件中的work_dir指定的。

*Important*: 配置文件的默认学习率是1个gpu和小批次大小为2,累计到64个批次大小进行梯度更新。

根据余弦败火规则,如果你使用不同的GPU或每个GPU的图像,你需要设置与批大小成比例的学习率,配置文件中的batch_sizesubdivisions确定。

使用单GPU训练

python tools/train.py ${CONFIG_FILE}

如果您想在命令中指定工作目录,可以添加一个参数--work_dir ${YOUR_WORK_DIR}。 例如采用YOLOv4训练模型:

python tools/train.py cfg/yolov4_coco_100e.py --validate

使用多gpu训练

python tools/train.py ${CONFIG_FILE} --gpus ${GPU_NUM} [optional arguments]

例如采用YOLOv4训练模型:

python tools/train.py cfg/yolov4_coco_100e.py --gpus 2 --validate

可选参数:

  • --validate(强烈建议):在训练epoch期间每一次k(默认值是1,可以像这样修改this)来执行评估。

  • --work_dir ${WORK_DIR}:覆盖配置文件中指定的工作目录。

  • --resume_from ${CHECKPOINT_FILE}:从以前训练的checkpoints文件恢复训练。

  • --multi-scale:多尺度缩放,尺寸范围为训练图片尺寸+/- 50%

resume_fromload_from的不同:

resume_from加载模型权重和优化器状态,并且训练也从指定的检查点继续训练。它通常用于恢复意外中断的训练。 load_from只加载模型权重,并且训练从epoch 0开始。它通常用于微调。

用于测试图像的高级api接口

下面是一个构建模型和测试给定图像的示例。

from yolodet.apis.inference import inference_detector,init_detector,show_result  
import os

config_file = 'cfg/yolov4_gpu.py'
checkpoint_file = 'work_dirs/yolov4/latest.pth'

# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# test a single image and show the results
img = 'test.jpg'  # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
show_result(img, result, model.CLASSES)
# or save the visualization results to image files
show_result(img, result, model.CLASSES, out_file='result.jpg')

# test a video and show the results
video = cv2.VideoCapture('video.mp4')
for frame in video:
    result = inference_detector(model, frame)
    show_result(frame, result, model.CLASSES, wait_time=1)