yolov5训练测试

    技术2022-07-11  140

    书接上回,下面测试一下yolov5的训练。 参考bilibili.com/video/BV1sv411B7jK。 (看完别忘给人投个币)。

    文章目录

    官方教程1.数据集下载2.启动tensorboard3.训练4.结果4.1 打印信息4.2 测试训练的权重4.2 Apex 5.其他尝试5.1 无初始权重训练

    官方教程

    官方tutorial(打不开的话,把整个仓库(迟早要下)下下来然后自己打开这个文件) 从这个位置开始读(前面工作在另一篇博客中,这里不再重复):

    1.数据集下载

    这一块即数据集下载,我是直接点的链接进行的下载,解压后放到yolov5仓库外面那层文件夹下,如下图。

    2.启动tensorboard

    我没用过这个所以先跳过。

    3.训练

    我这修改了一下,复制一份yolov5s.pt文件,重命名为test1.pt作为权重训练,故我在命令行中的输入为:

    PS E:\self_study\git\yolov5> python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights test1.pt --name tutorial --nosave --cache

    4.结果

    4.1 打印信息

    还有很多信息没看懂,但这应该算训练完成了。

    4.2 测试训练的权重

    测试inference中的两张图,没啥问题。

    PS E:\self_study\git\yolov5> python detect.py --weights weights/last_tutorial.pt --img 416 --conf 0.4 --source ./inference/images/ Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', fourcc='mp4v', half=False, img_size=416, iou_thres=0.5, output='inference/output', save_txt=False, source='./inference/images/', view_img=False, weights='weights/last_tutorial.pt') Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1060', total_memory=6144MB) image 1/2 inference\images\bus.jpg: 416x352 3 persons, 1 buss, Done. (0.026s) image 2/2 inference\images\zidane.jpg: 288x416 2 persons, 2 ties, Done. (0.027s) Results saved to E:\self_study\git\yolov5\inference/output Done. (6.844s)

    4.2 Apex

    有个很烦的提示(可以忽略),要Apex(混合精度,加快训练速度)。

    Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex {'lr0': 0.01, 'momentum': 0.937, 'weight_decay': 0.0005, 'giou': 0.05, 'cls': 0.58, 'cls_pw': 1.0, 'obj': 1.0, 'obj_pw': 1.0, 'iou_t': 0.2, 'anchor_t': 4.0, 'fl_gamma': 0.0, 'hsv_h': 0.014, 'hsv_s': 0.68, 'hsv_v': 0.36, 'degrees': 0.0, 'translate': 0.0, 'scale': 0.5, 'shear': 0.0}

    参考一文详解Apex的安装和使用教程(一款基于 PyTorch 的混合精度训练加速神器) 装一下:

    E:\Program Files\apex>python setup.py install 。。。省略。。。。 Finished processing dependencies for apex==0.1

    再来一遍训练试试: 这次改个名字

    PS E:\self_study\git\yolov5> python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights test1.pt --name test1 --nosave --cache 。。。省略 Optimizer stripped from weights\last_test1.pt 5 epochs completed in 0.118 hours.

    貌似是快了点。

    下次更新个别的数据集的训练和测试。

    5.其他尝试

    5.1 无初始权重训练

    命令行输入:

    PS E:\self_study\git\yolov5> python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --name test2 --nosave --cache

    可以训练出一个权重,效果极差,证明是用随机权重开始的训练。

    Processed: 0.010, SQL: 9