yolov7

yolov7

实时目标检测算法实现性能新突破

YOLOv7是一款高效的实时目标检测算法,在MS COCO数据集上实现了51.4% AP的性能。该项目提供多种模型变体,包括YOLOv7-X和YOLOv7-W6等,适用于不同应用场景。此外,YOLOv7还具备姿态估计和实例分割功能,支持多GPU训练、迁移学习和模型导出,是一个全面的目标检测解决方案。

YOLOv7目标检测深度学习计算机视觉性能优化Github开源项目

官方YOLOv7

论文实现 - YOLOv7: 可训练的免费技巧集合为实时目标检测器创造新的最先进水平

PWC Hugging Face Spaces <a href="https://colab.research.google.com/gist/AlexeyAB/b769f5795e65fdab80086f6cb7940dae/yolov7detection.ipynb"><img src="https://yellow-cdn.veclightyear.com/ab5030c0/e8e3fca1-4a58-4290-bc03-1623aed4a9d5.svg" alt="在Colab中打开"></a> arxiv.org

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/b2b27972-ef43-4439-a9bb-9e906571696a.png" width="79%"/> </a> </div>

网页演示

性能

MS COCO

模型测试尺寸AP<sup>test</sup>AP<sub>50</sub><sup>test</sup>AP<sub>75</sub><sup>test</sup>batch 1 fpsbatch 32 平均时间
YOLOv764051.4%69.7%55.9%161 fps2.8 ms
YOLOv7-X64053.1%71.2%57.8%114 fps4.3 ms
YOLOv7-W6128054.9%72.6%60.1%84 fps7.6 ms
YOLOv7-E6128056.0%73.5%61.2%56 fps12.3 ms
YOLOv7-D6128056.6%74.0%61.8%44 fps15.0 ms
YOLOv7-E6E128056.8%74.4%62.1%36 fps18.7 ms

安装

Docker环境(推荐)

<details><summary> <b>展开</b> </summary>
# 创建docker容器,如果你有更多内存,可以更改共享内存大小。 nvidia-docker run --name yolov7 -it -v 你的coco路径/:/coco/ -v 你的代码路径/:/yolov7 --shm-size=64g nvcr.io/nvidia/pytorch:21.08-py3 # apt安装所需包 apt update apt install -y zip htop screen libgl1-mesa-glx # pip安装所需包 pip install seaborn thop # 进入代码文件夹 cd /yolov7
</details>

测试

yolov7.pt yolov7x.pt yolov7-w6.pt yolov7-e6.pt yolov7-d6.pt yolov7-e6e.pt

python test.py --data data/coco.yaml --img 640 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights yolov7.pt --name yolov7_640_val

你将得到以下结果:

 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.51206
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.69730
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.55521
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.35247
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.55937
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.66693
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.38453
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.63765
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.68772
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.53766
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.73549
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.83868

要测量准确度,请下载COCO-annotations for Pycocotools./coco/annotations/instances_val2017.json

训练

数据准备

bash scripts/get_coco.sh
  • 下载MS COCO数据集图像(训练集验证集测试集)和标签。如果你之前使用过不同版本的YOLO,我们强烈建议你删除train2017.cacheval2017.cache文件,并重新下载标签

单GPU训练

# 训练 p5 模型 python train.py --workers 8 --device 0 --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml # 训练 p6 模型 python train_aux.py --workers 8 --device 0 --batch-size 16 --data data/coco.yaml --img 1280 1280 --cfg cfg/training/yolov7-w6.yaml --weights '' --name yolov7-w6 --hyp data/hyp.scratch.p6.yaml

多 GPU 训练

# 训练 p5 模型 python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 8 --device 0,1,2,3 --sync-bn --batch-size 128 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml # 训练 p6 模型 python -m torch.distributed.launch --nproc_per_node 8 --master_port 9527 train_aux.py --workers 8 --device 0,1,2,3,4,5,6,7 --sync-bn --batch-size 128 --data data/coco.yaml --img 1280 1280 --cfg cfg/training/yolov7-w6.yaml --weights '' --name yolov7-w6 --hyp data/hyp.scratch.p6.yaml

迁移学习

yolov7_training.pt yolov7x_training.pt yolov7-w6_training.pt yolov7-e6_training.pt yolov7-d6_training.pt yolov7-e6e_training.pt

单 GPU 微调自定义数据集

# 微调 p5 模型 python train.py --workers 8 --device 0 --batch-size 32 --data data/custom.yaml --img 640 640 --cfg cfg/training/yolov7-custom.yaml --weights 'yolov7_training.pt' --name yolov7-custom --hyp data/hyp.scratch.custom.yaml # 微调 p6 模型 python train_aux.py --workers 8 --device 0 --batch-size 16 --data data/custom.yaml --img 1280 1280 --cfg cfg/training/yolov7-w6-custom.yaml --weights 'yolov7-w6_training.pt' --name yolov7-w6-custom --hyp data/hyp.scratch.custom.yaml

重参数化

参见 reparameterization.ipynb

推理

对视频进行推理:

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source yourvideo.mp4

对图片进行推理:

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg
<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/086fbed2-e8d7-44cd-83c2-7ca8fd35f32a.jpg" width="59%"/> </a> </div>

导出

Pytorch 转 CoreML (并在 MacOS/iOS 上进行推理) <a href="https://colab.research.google.com/github/WongKinYiu/yolov7/blob/main/tools/YOLOv7CoreML.ipynb"><img src="https://yellow-cdn.veclightyear.com/ab5030c0/e8e3fca1-4a58-4290-bc03-1623aed4a9d5.svg" alt="在 Colab 中打开"></a>

Pytorch 转 ONNX 并包含 NMS (并进行推理) <a href="https://colab.research.google.com/github/WongKinYiu/yolov7/blob/main/tools/YOLOv7onnx.ipynb"><img src="https://yellow-cdn.veclightyear.com/ab5030c0/e8e3fca1-4a58-4290-bc03-1623aed4a9d5.svg" alt="在 Colab 中打开"></a>

python export.py --weights yolov7-tiny.pt --grid --end2end --simplify \ --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640

Pytorch 转 TensorRT 并包含 NMS (并进行推理) <a href="https://colab.research.google.com/github/WongKinYiu/yolov7/blob/main/tools/YOLOv7trt.ipynb"><img src="https://yellow-cdn.veclightyear.com/ab5030c0/e8e3fca1-4a58-4290-bc03-1623aed4a9d5.svg" alt="在 Colab 中打开"></a>

wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-tiny.pt python export.py --weights ./yolov7-tiny.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 git clone https://github.com/Linaom1214/tensorrt-python.git python ./tensorrt-python/export.py -o yolov7-tiny.onnx -e yolov7-tiny-nms.trt -p fp16

Pytorch 转 TensorRT 的另一种方法 <a href="https://colab.research.google.com/gist/AlexeyAB/fcb47ae544cf284eb24d8ad8e880d45c/yolov7trtlinaom.ipynb"><img src="https://yellow-cdn.veclightyear.com/ab5030c0/e8e3fca1-4a58-4290-bc03-1623aed4a9d5.svg" alt="在 Colab 中打开"></a> <details><summary> <b>展开</b> </summary>

wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-tiny.pt python export.py --weights yolov7-tiny.pt --grid --include-nms git clone https://github.com/Linaom1214/tensorrt-python.git python ./tensorrt-python/export.py -o yolov7-tiny.onnx -e yolov7-tiny-nms.trt -p fp16 # 或使用 trtexec 将 ONNX 转换为 TensorRT 引擎 /usr/src/tensorrt/bin/trtexec --onnx=yolov7-tiny.onnx --saveEngine=yolov7-tiny-nms.trt --fp16
</details>

测试环境: Python 3.7.13, Pytorch 1.12.0+cu113

姿态估计

代码 yolov7-w6-pose.pt

参见 keypoint.ipynb

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/17d72b52-4217-4edc-a81a-e9b31738e91f.png" width="39%"/> </a> </div>

实例分割 (与 NTU 合作)

代码 yolov7-mask.pt

参见 instance.ipynb

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/e3ab4298-ddd3-41a1-a094-e9eb161b03b9.png" width="59%"/> </a> </div>

实例分割

代码 yolov7-seg.pt

YOLOv7 用于实例分割 (YOLOR + YOLOv5 + YOLACT)

模型测试尺寸AP<sup></sup>AP<sub>50</sub><sup></sup>AP<sub>75</sub><sup></sup>AP<sup>掩码</sup>AP<sub>50</sub><sup>掩码</sup>AP<sub>75</sub><sup>掩码</sup>
YOLOv7-seg64051.4%69.4%55.8%41.5%65.5%43.7%

无锚点检测头

代码 yolov7-u6.pt

带解耦TAL头的YOLOv7(YOLOR + YOLOv5 + YOLOv6)

模型测试尺寸AP<sup>验证</sup>AP<sub>50</sub><sup>验证</sup>AP<sub>75</sub><sup>验证</sup>
YOLOv7-u664052.6%69.7%57.3%

引用

@inproceedings{wang2023yolov7,
  title={{YOLOv7}: 可训练的免费附加功能集为实时目标检测器树立新标准},
  author={Wang, Chien-Yao and Bochkovskiy, Alexey and Liao, Hong-Yuan Mark},
  booktitle={IEEE/CVF计算机视觉与模式识别会议论文集(CVPR)},
  year={2023}
}
@article{wang2023designing,
  title={通过梯度路径分析设计网络设计策略},
  author={Wang, Chien-Yao and Liao, Hong-Yuan Mark and Yeh, I-Hau},
  journal={信息科学与工程学报},
  year={2023}
}

预告

YOLOv7-语义分割 & YOLOv7-全景分割 & YOLOv7-图像描述

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/0fd37634-d77b-40e0-bbeb-36a884d7e5df.jpg" width="24%"/> </a> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/67f9e063-56f8-4986-9930-3752a80b5406.jpg" width="24%"/> </a> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/4ffb40b3-c8ce-496e-a688-b22783b208aa.png" width="24%"/> </a> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/7f7135c5-72ed-4fdb-8f8e-2421a2e57bcb.png" width="24%"/> </a> </div>

YOLOv7-语义分割 & YOLOv7-目标检测 & YOLOv7-深度估计(与NTUT合作)

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/38640b71-1f35-4030-ba26-b39a2665e93d.jpg" width="80%"/> </a> </div>

YOLOv7-3D检测 & YOLOv7-激光雷达 & YOLOv7-道路(与NTUT合作)

<div align="center"> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/43a264c9-273b-4397-887c-4612d9244960.jpg" width="30%"/> </a> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/3292ad79-2795-4463-9b93-38eb151665a8.jpg" width="30%"/> </a> <a href="./"> <img src="https://yellow-cdn.veclightyear.com/ab5030c0/af1c665e-c981-4ee3-bcc8-7a280d4aacc9.jpg" width="30%"/> </a> </div>

致谢

<details><summary> <b>展开</b> </summary> </details>

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多