基于Paddlepaddle复现yolov5,支持PaddleDetection接口

Overview

PaddleDetection yolov5

https://github.com/Sharpiless/PaddleDetection-Yolov5

简介

PaddleDetection飞桨目标检测开发套件,旨在帮助开发者更快更好地完成检测模型的组建、训练、优化及部署等全开发流程。

PaddleDetection模块化地实现了多种主流目标检测算法,提供了丰富的数据增强策略、网络模块组件(如骨干网络)、损失函数等,并集成了模型压缩和跨平台高性能部署能力。

经过长时间产业实践打磨,PaddleDetection已拥有顺畅、卓越的使用体验,被工业质检、遥感图像检测、无人巡检、新零售、互联网、科研等十多个行业的开发者广泛应用。

Yolov5:

YOLOV4出现之后不久,YOLOv5横空出世。YOLOv5在YOLOv4算法的基础上做了进一步的改进,检测性能得到进一步的提升。虽然YOLOv5算法并没有与YOLOv4算法进行性能比较与分析,但是YOLOv5在COCO数据集上面的测试效果还是挺不错的。大家对YOLOv5算法的创新性半信半疑,有的人对其持肯定态度,有的人对其持否定态度。在我看来,YOLOv5检测算法中还是存在很多可以学习的地方,虽然这些改进思路看来比较简单或者创新点不足,但是它们确定可以提升检测算法的性能。其实工业界往往更喜欢使用这些方法,而不是利用一个超级复杂的算法来获得较高的检测精度。本文将对YOLOv5检测算法进行复现。

下载预训练模型:

https://drive.google.com/file/d/16tREOOJzKgOLw31bSiUNz0iBdqoRzq1i/view?usp=sharing

训练Yolov5:

python tools/train.py -c configs/yolov5/yolov5s_CSPdarknet_roadsign.yml

实验结果:

0.9087 mAP on roadsign dataset.

01

01

关注我的公众号:

感兴趣的同学关注我的公众号——可达鸭的深度学习教程:

在这里插入图片描述

联系作者:

B站:https://space.bilibili.com/470550823

CSDN:https://blog.csdn.net/weixin_44936889

AI Studio:https://aistudio.baidu.com/aistudio/personalcenter/thirdview/67156

Github:https://github.com/Sharpiless

%cd work/
/home/aistudio/work
!unzip PPDet-yolov5v2.zip -d ./
!python tools/train.py -c configs/yolov5/yolov5s_CSPdarknet_roadsign.yml --eval
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
[07/15 10:17:41] ppdet.utils.download WARNING: Config annotation dataset/roadsign_voc/train.txt is not a file, dataset config is not valid
[07/15 10:17:41] ppdet.utils.download INFO: Dataset /home/aistudio/work/dataset/roadsign_voc is not valid for reason above, try searching /home/aistudio/.cache/paddle/dataset or downloading dataset...
[07/15 10:17:41] ppdet.utils.download INFO: Found /home/aistudio/.cache/paddle/dataset/roadsign_voc/annotations
[07/15 10:17:41] ppdet.utils.download INFO: Found /home/aistudio/.cache/paddle/dataset/roadsign_voc/images
[07/15 10:17:41] reader WARNING: Shared memory size is less than 1G, disable shared_memory in DataLoader
[07/15 10:17:42] ppdet.utils.checkpoint INFO: Finish loading model weights: output.pdparams
[07/15 10:17:51] ppdet.engine INFO: Epoch: [0] [ 0/87] learning_rate: 0.000033 loss_xy: 0.752040 loss_wh: 0.698217 loss_iou: 2.634957 loss_obj: 11.301561 loss_cls: 1.041652 loss: 16.428429 eta: 8:28:32 batch_cost: 8.7679 data_cost: 0.9061 ips: 0.9124 images/s
[07/15 10:19:42] ppdet.engine INFO: Epoch: [0] [20/87] learning_rate: 0.000047 loss_xy: 0.529626 loss_wh: 0.569290 loss_iou: 2.436198 loss_obj: 8.576855 loss_cls: 1.023474 loss: 13.317031 eta: 5:29:28 batch_cost: 5.5608 data_cost: 0.0002 ips: 1.4386 images/s
[07/15 10:21:42] ppdet.engine INFO: Epoch: [0] [40/87] learning_rate: 0.000060 loss_xy: 0.500230 loss_wh: 0.502719 loss_iou: 2.226187 loss_obj: 4.208471 loss_cls: 0.890207 loss: 8.235611 eta: 5:35:40 batch_cost: 6.0032 data_cost: 0.0003 ips: 1.3326 images/s
[07/15 10:23:23] ppdet.engine INFO: Epoch: [0] [60/87] learning_rate: 0.000073 loss_xy: 0.519860 loss_wh: 0.599364 loss_iou: 2.455585 loss_obj: 3.626266 loss_cls: 1.031202 loss: 8.345335 eta: 5:18:38 batch_cost: 5.0474 data_cost: 0.0003 ips: 1.5850 images/s
[07/15 10:25:13] ppdet.engine INFO: Epoch: [0] [80/87] learning_rate: 0.000087 loss_xy: 0.568008 loss_wh: 0.618775 loss_iou: 2.583227 loss_obj: 3.632595 loss_cls: 0.863238 loss: 7.575019 eta: 5:15:29 batch_cost: 5.4984 data_cost: 0.0002 ips: 1.4550 images/s
[07/15 10:25:47] ppdet.utils.checkpoint INFO: Save checkpoint: output/yolov5s_CSPdarknet_roadsign
[07/15 10:25:47] ppdet.utils.download WARNING: Config annotation dataset/roadsign_voc/valid.txt is not a file, dataset config is not valid
[07/15 10:25:47] ppdet.utils.download INFO: Dataset /home/aistudio/work/dataset/roadsign_voc is not valid for reason above, try searching /home/aistudio/.cache/paddle/dataset or downloading dataset...
[07/15 10:25:47] ppdet.utils.download INFO: Found /home/aistudio/.cache/paddle/dataset/roadsign_voc/annotations
[07/15 10:25:47] ppdet.utils.download INFO: Found /home/aistudio/.cache/paddle/dataset/roadsign_voc/images
[07/15 10:25:48] ppdet.engine INFO: Eval iter: 0
[07/15 10:26:09] ppdet.engine INFO: Eval iter: 100
[07/15 10:26:25] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[07/15 10:26:25] ppdet.metrics.metrics INFO: mAP(0.50, integral) = 85.84%
[07/15 10:26:25] ppdet.engine INFO: Total sample number: 176, averge FPS: 4.751870228058035
[07/15 10:26:25] ppdet.engine INFO: Best test bbox ap is 0.858.
[07/15 10:26:25] ppdet.utils.checkpoint INFO: Save checkpoint: output/yolov5s_CSPdarknet_roadsign
[07/15 10:26:35] ppdet.engine INFO: Epoch: [1] [ 0/87] learning_rate: 0.000091 loss_xy: 0.567437 loss_wh: 0.623783 loss_iou: 2.511684 loss_obj: 3.314124 loss_cls: 0.949793 loss: 7.338743 eta: 5:16:15 batch_cost: 6.2481 data_cost: 0.0003 ips: 1.2804 images/s
[07/15 10:28:39] ppdet.engine INFO: Epoch: [1] [20/87] learning_rate: 0.000100 loss_xy: 0.583728 loss_wh: 0.708465 loss_iou: 2.704193 loss_obj: 3.461134 loss_cls: 1.127932 loss: 9.057523 eta: 5:20:59 batch_cost: 6.2270 data_cost: 0.0003 ips: 1.2847 images/s
[07/15 10:30:28] ppdet.engine INFO: Epoch: [1] [40/87] learning_rate: 0.000100 loss_xy: 0.576615 loss_wh: 0.655194 loss_iou: 2.566234 loss_obj: 2.921384 loss_cls: 1.010778 loss: 7.844104 eta: 5:16:43 batch_cost: 5.4392 data_cost: 0.0003 ips: 1.4708 images/s
[07/15 10:32:34] ppdet.engine INFO: Epoch: [1] [60/87] learning_rate: 0.000100 loss_xy: 0.583071 loss_wh: 0.726098 loss_iou: 2.730413 loss_obj: 3.053501 loss_cls: 0.991524 loss: 8.496977 eta: 5:19:40 batch_cost: 6.3128 data_cost: 0.0003 ips: 1.2673 images/s
[07/15 10:34:31] ppdet.engine INFO: Epoch: [1] [80/87] learning_rate: 0.000100 loss_xy: 0.606061 loss_wh: 0.652358 loss_iou: 2.841094 loss_obj: 3.237591 loss_cls: 1.084277 loss: 8.605825 eta: 5:18:16 batch_cost: 5.8318 data_cost: 0.0003 ips: 1.3718 images/s
[07/15 10:34:59] ppdet.utils.checkpoint INFO: Save checkpoint: output/yolov5s_CSPdarknet_roadsign
[07/15 10:35:00] ppdet.engine INFO: Eval iter: 0
[07/15 10:35:19] ppdet.engine INFO: Eval iter: 100
[07/15 10:35:33] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[07/15 10:35:33] ppdet.metrics.metrics INFO: mAP(0.50, integral) = 85.30%
[07/15 10:35:33] ppdet.engine INFO: Total sample number: 176, averge FPS: 5.151774310709877
[07/15 10:35:33] ppdet.engine INFO: Best test bbox ap is 0.858.
[07/15 10:35:46] ppdet.engine INFO: Epoch: [2] [ 0/87] learning_rate: 0.000100 loss_xy: 0.537015 loss_wh: 0.587401 loss_iou: 2.352699 loss_obj: 3.121367 loss_cls: 1.012583 loss: 7.857001 eta: 5:17:11 batch_cost: 5.8271 data_cost: 0.0003 ips: 1.3729 images/s
^C
!rm -rf output/
!zip -r code.zip ./*
You might also like...
Comments
  • CVE-2007-4559 Patch

    CVE-2007-4559 Patch

    Patching CVE-2007-4559

    Hi, we are security researchers from the Advanced Research Center at Trellix. We have began a campaign to patch a widespread bug named CVE-2007-4559. CVE-2007-4559 is a 15 year old bug in the Python tarfile package. By using extract() or extractall() on a tarfile object without sanitizing input, a maliciously crafted .tar file could perform a directory path traversal attack. We found at least one unsantized extractall() in your codebase and are providing a patch for you via pull request. The patch essentially checks to see if all tarfile members will be extracted safely and throws an exception otherwise. We encourage you to use this patch or your own solution to secure against CVE-2007-4559. Further technical information about the vulnerability can be found in this blog.

    If you have further questions you may contact us through this projects lead researcher Kasimir Schulz.

    opened by TrellixVulnTeam 0
  • IndexError: list index out of range

    IndexError: list index out of range

    Traceback (most recent call last):

    File "tools/train.py", line 141, in

    main()
    

    File "tools/train.py", line 137, in main

    run(FLAGS, cfg)
    

    File "tools/train.py", line 103, in run

    trainer = Trainer(cfg, mode='train')
    

    File "/root/paddlejob/workspace/code/PaddleDetection-yolov5/ppdet/engine/trainer.py", line 97, in init

    self.lr = create('LearningRate')(steps_per_epoch)
    

    File "/root/paddlejob/workspace/code/PaddleDetection-yolov5/ppdet/optimizer.py", line 201, in call

    boundary, value = self.schedulers[1](self.base_lr, step_per_epoch)
    

    IndexError: list index out of range

    opened by gaorui999 0
  • yoloV5 L  模型训练没问题infer报错

    yoloV5 L 模型训练没问题infer报错

    yoloV5 L 模型训练没问题infer报错:
    File "/home/aistudio/work/ppdet/modeling/ops.py", line 820, in ops_yolo_box_v5 p = x.reshape((bs, nA, class_num + 5, nG,nG)).transform((0, 1, 3, 4, 2)).contiguous() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/manipulation.py", line 1582, in reshape return paddle.fluid.layers.reshape(x=x, shape=shape, name=name) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/nn.py", line 6142, in reshape out, _ = core.ops.reshape2(x, None, 'shape', shape) ValueError: (InvalidArgument) The 'shape' in ReshapeOp is invalid. The input tensor X'size must be equal to the capacity of 'shape'. But received X's shape = [1, 21, 20, 20], X's size = 8400, 'shape' is [1, 6, 7, 20, 20], the capacity of 'shape' is 16800. [Hint: Expected capacity == in_size, but received capacity:16800 != in_size:8400.] (at /paddle/paddle/fluid/operators/reshape_op.cc:222) [operator < reshape2 > error]

    opened by GanWang 0
  • tools/export_model.py error

    tools/export_model.py error

    python tools/export_model.py --config ... runnning error.

       File "/tmp/tmpn07wvto_.py", line 27, in forward
    	false_fn_1, (), (), (out,))
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 210, in convert_ifelse
    	return _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args)
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 235, in _run_py_ifelse
    	return true_fn(*true_args) if pred else false_fn(*false_args)
        File "/mnt/disk_2t/shaoxiong/handpp_work/research/PaddleDetection-Yolov5/ppdet/modeling/architectures/meta_arch.py", line 28, in forward (* user code *)
    	out = self.get_pred()
        File "/mnt/disk_2t/shaoxiong/handpp_work/research/PaddleDetection-Yolov5/ppdet/modeling/architectures/yolo.py", line 201, in get_pred (* user code *)
    	return self._forward()
        File "/mnt/disk_2t/shaoxiong/handpp_work/research/PaddleDetection-Yolov5/ppdet/modeling/architectures/yolo.py", line 160, in _forward (* user code *)
    	body_feats = self.backbone(self.inputs)
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 898, in __call__
    	outputs = self.forward(*inputs, **kwargs)
        File "/tmp/tmp7igr6af4.py", line 29, in forward
    	for_loop_condition_0, for_loop_body_0, [__for_loop_var_index_1, x, i])
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 44, in convert_while_loop
    	loop_vars = _run_py_while(cond, body, loop_vars)
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 58, in _run_py_while
    	loop_vars = body(*loop_vars)
        File "/mnt/disk_2t/shaoxiong/handpp_work/research/PaddleDetection-Yolov5/ppdet/modeling/backbones/cspdarknet.py", line 48, in forward (* user code *)
    	x = m(x)  # run
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 898, in __call__
    	outputs = self.forward(*inputs, **kwargs)
        File "/mnt/disk_2t/shaoxiong/handpp_work/research/PaddleDetection-Yolov5/ppdet/modeling/architectures/common.py", line 227, in forward (* user code *)
    	y = paddle.concat([x[:, :, ::2, ::2], x[:, :, 1::2, ::2], x[:, :, ::2, 1::2], x[:, :, 1::2, 1::2]], 1)
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/framework.py", line 1832, in __getitem__
    	return _getitem_impl_(self, item)
        File "/home/ar/shaoxiong/envs/anaconda3/envs/mobilehand/lib/python3.7/site-packages/paddle/fluid/framework.py", line 831, in _getitem_impl_
    	assert (step == -1)
        AssertionError
    
    
    opened by youngstu 3
Owner
BIT可达鸭
null