当前位置:   article > 正文

手把手教你运行YOLOv6(超详细)

yolov6

YOLOv6 是美团视觉智能部研发的一款目标检测框架,致力于工业应用。本框架同时专注于检测的精度和推理效率,在工业界常用的尺寸模型中:YOLOv6-nano 在 COCO 上精度可达 35.0% AP,在 T4 上推理速度可达 1242 FPS;YOLOv6-s 在 COCO 上精度可达 43.1% AP,在 T4 上推理速度可达 520 FPS。在部署方面,YOLOv6 支持 GPU(TensorRT)、CPU(OPENVINO)、ARM(MNN、TNN、NCNN)等不同平台的部署,极大地简化工程部署时的适配工作。

YOLOv6 GitHub网址:美团/YOLOv6:YOLOv6:专用于工业应用的单级物体检测框架。 (github.com)

记得把对应版本的模型也下载,我下的是YOLOv6-s

终端输入 pip install requirements.txt,YOLOv6比V5多了一个addict库,也可以只下载一个addict

打开程序,找到文件夹tools->infer.py

 

 默认的路径需要改一下,否则会显示找不到文件,不想动手的就直接复制下面的吧

  1. #!/usr/bin/env python3
  2. # -*- coding:utf-8 -*-
  3. import argparse
  4. import os
  5. import sys
  6. import os.path as osp
  7. import torch
  8. ROOT = os.getcwd()
  9. if str(ROOT) not in sys.path:
  10. sys.path.append(str(ROOT))
  11. from yolov6.utils.events import LOGGER
  12. from yolov6.core.inferer import Inferer
  13. def get_args_parser(add_help=True):
  14. parser = argparse.ArgumentParser(description='YOLOv6 PyTorch Inference.', add_help=add_help)
  15. parser.add_argument('--weights', type=str, default='../weights/yolov6s.pt', help='model path(s) for inference.')
  16. parser.add_argument('--source', type=str, default='../data/images', help='the source path, e.g. image-file/dir.')
  17. parser.add_argument('--yaml', type=str, default='../data/coco.yaml', help='data yaml file.')
  18. parser.add_argument('--img-size', type=int, default=640, help='the image-size(h,w) in inference size.')
  19. parser.add_argument('--conf-thres', type=float, default=0.25, help='confidence threshold for inference.')
  20. parser.add_argument('--iou-thres', type=float, default=0.45, help='NMS IoU threshold for inference.')
  21. parser.add_argument('--max-det', type=int, default=1000, help='maximal inferences per image.')
  22. parser.add_argument('--device', default='0', help='device to run our model i.e. 0 or 0,1,2,3 or cpu.')
  23. parser.add_argument('--save-txt', action='store_true', help='save results to *.txt.')
  24. parser.add_argument('--save-img', action='store_false', help='save visuallized inference results.')
  25. parser.add_argument('--classes', nargs='+', type=int, help='filter by classes, e.g. --classes 0, or --classes 0 2 3.')
  26. parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS.')
  27. parser.add_argument('--project', default='runs/inference', help='save inference results to project/name.')
  28. parser.add_argument('--name', default='exp', help='save inference results to project/name.')
  29. parser.add_argument('--hide-labels', default=False, action='store_true', help='hide labels.')
  30. parser.add_argument('--hide-conf', default=False, action='store_true', help='hide confidences.')
  31. parser.add_argument('--half', action='store_true', help='whether to use FP16 half-precision inference.')
  32. args = parser.parse_args()
  33. LOGGER.info(args)
  34. return args
  35. @torch.no_grad()
  36. def run(weights=osp.join(ROOT, 'yolov6s.pt'),
  37. source=osp.join(ROOT, 'data/images'),
  38. yaml=None,
  39. img_size=640,
  40. conf_thres=0.25,
  41. iou_thres=0.45,
  42. max_det=1000,
  43. device='',
  44. save_txt=False,
  45. save_img=True,
  46. classes=None,
  47. agnostic_nms=False,
  48. project=osp.join(ROOT, 'runs/inference'),
  49. name='exp',
  50. hide_labels=False,
  51. hide_conf=False,
  52. half=False,
  53. ):
  54. """ Inference process
  55. This function is the main process of inference, supporting image files or dirs containing images.
  56. Args:
  57. weights: The path of model.pt, e.g. yolov6s.pt
  58. source: Source path, supporting image files or dirs containing images.
  59. yaml: Data yaml file, .
  60. img_size: Inference image-size, e.g. 640
  61. conf_thres: Confidence threshold in inference, e.g. 0.25
  62. iou_thres: NMS IOU threshold in inference, e.g. 0.45
  63. max_det: Maximal detections per image, e.g. 1000
  64. device: Cuda device, e.e. 0, or 0,1,2,3 or cpu
  65. save_txt: Save results to *.txt
  66. save_img: Save visualized inference results
  67. classes: Filter by class: --class 0, or --class 0 2 3
  68. agnostic_nms: Class-agnostic NMS
  69. project: Save results to project/name
  70. name: Save results to project/name, e.g. 'exp'
  71. line_thickness: Bounding box thickness (pixels), e.g. 3
  72. hide_labels: Hide labels, e.g. False
  73. hide_conf: Hide confidences
  74. half: Use FP16 half-precision inference, e.g. False
  75. """
  76. # create save dir
  77. save_dir = osp.join(project, name)
  78. if (save_img or save_txt) and not osp.exists(save_dir):
  79. os.makedirs(save_dir)
  80. else:
  81. LOGGER.warning('Save directory already existed')
  82. if save_txt:
  83. os.mkdir(osp.join(save_dir, 'labels'))
  84. # Inference
  85. inferer = Inferer(source, weights, device, yaml, img_size, half)
  86. inferer.infer(conf_thres, iou_thres, classes, agnostic_nms, max_det, save_dir, save_txt, save_img, hide_labels, hide_conf)
  87. if save_txt or save_img:
  88. LOGGER.info(f"Results saved to {save_dir}")
  89. def main(args):
  90. run(**vars(args))
  91. if __name__ == "__main__":
  92. args = get_args_parser()
  93. main(args)

创建一个weights文件夹,将在官网下载好的yolov6s.pt模型放进去

 再找到文件夹yolov6->core->inferer.py文件中168行,在路径加个点,果然初版还是不够完善啊!

 这里就配置完了,运行infer.py文件

测试效果路径在tools文件夹里

 

我用YOLOv5测试对比一下:

 总结:

YOLOv6的精度和置信度确实比YOLOv5要好一些,但是误检率太高,并且版本维护更新速度太慢,不适合用于工业领域,自己测着玩还行。

YOLOv6训练自己的数据集在下篇博文

最新版YOLOv6训练自己的数据集(超详细完整版!)https://blog.csdn.net/qq_58355216/article/details/125525243?spm=1001.2014.3001.5501

YOLOV7

近日官方发布了YOLOv7,碾压一切YOLO,感兴趣的可以去看一下

YOLOv7训练自己的数据集(超详细)_Mr Dinosaur的博客-CSDN博客https://blog.csdn.net/qq_58355216/article/details/125677147?spm=1001.2014.3001.5502

--------------------------------------------更新线---------------------------------------------

YOLOV8

期待已久的YOLOV8,比V5、V6、V7更快更准,方法已写好,快来试一试吧

YOLOv8训练自己的数据集https://blog.csdn.net/qq_58355216/article/details/128671030?spm=1001.2014.3001.5501

结尾点个赞支持一下吧,将会是我更新的动力!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/418196
推荐阅读
相关标签
  

闽ICP备14008679号