ultralytics /yolov5
Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.
★ 58,272⑂ 17,434👁 379⑃ 3,071● 9,428▤ 10
TA的项目
+5
日增长
+17
周增长
+92
月增长
58,272
stars
17,434
forks
379
watchers
3,071
prs
9,428
issues
10
releases
README
中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية
Ultralytics YOLOv5 🚀 是由 Ultralytics 开发的一款快速、准确且易于使用的计算机视觉模型。基于 PyTorch 框架,YOLOv5 以其速度、准确性和简洁性而闻名。它融合了广泛研究和开发的见解与最佳实践,使其成为各种视觉 AI 任务中热门而可靠的选择,包括目标检测、图像分割和图像分类。
我们希望这里的资源能帮助您充分利用 YOLOv5。请浏览 YOLOv5 文档获取详细信息,在 GitHub 上提出 issue 以获得支持,并加入我们的 Discord 社区进行提问和讨论!
如需申请企业许可证,请填写 Ultralytics 授权许可 表格。
🚀 探索 Ultralytics YOLO 生态系统
YOLOv5 是一个成熟、经过生产验证的模型,仍然是快速可靠的目标检测、实例分割和图像分类的绝佳选择。如果您的项目需要最新的架构、姿态估计和旋转目标检测 (OBB)等额外任务,或统一的 Python 与 CLI 接口,那么持续维护的 ultralytics 包将最新的 Ultralytics YOLO 模型汇集于一处。浏览 Ultralytics 文档以找到最适合您用例的方案。
bash
安装 ultralytics 包以获取最新的 Ultralytics YOLO 模型
pip install ultralytics
📚 文档
请参阅 YOLOv5 文档,了解有关训练、测试和部署的完整文档。请参阅下方的快速入门示例。
安装
克隆仓库并在 Python=3.8.0 环境中安装依赖项。确保您已安装 PyTorch=1.8。
bash
克隆 YOLOv5 仓库
git clone https://github.com/ultralytics/yolov5
导航到克隆的目录
cd yolov5
安装所需的包
pip install -r requirements.txt
使用 PyTorch Hub 进行推理
通过 PyTorch Hub 使用 YOLOv5 进行推理。模型 会自动从最新的 YOLOv5 发布版本下载。
python
import torch
加载 YOLOv5 模型 (选项: yolov5n, yolov5s, yolov5m, yolov5l, yolov5x)
model = torch.hub.load("ultralytics/yolov5", "yolov5s") 默认: yolov5s
定义输入图像源 (URL、本地文件、PIL 图像、OpenCV 帧、numpy 数组或列表)
img = "https://ultralytics.com/images/zidane.jpg" 示例图像
执行推理 (自动处理批处理、调整大小、归一化)
results = model(img)
处理结果 (选项: .print(), .show(), .save(), .crop(), .pandas())
results.print() 将结果打印到控制台
results.show() 在窗口中显示结果
results.save() 将结果保存到 runs/detect/exp
使用 detect.py 进行推理
detect.py 脚本在各种来源上运行推理。它会自动从最新的 YOLOv5 发布版本下载模型,并将结果保存到 runs/detect 目录。
bash
使用网络摄像头运行推理
python detect.py --weights yolov5s.pt --source 0
对本地图像文件运行推理
python detect.py --weights yolov5s.pt --source img.jpg
对本地视频文件运行推理
python detect.py --weights yolov5s.pt --source vid.mp4
对屏幕截图运行推理
python detect.py --weights yolov5s.pt --source screen
对图像目录运行推理
python detect.py --weights yolov5s.pt --source path/to/images/
对列出图像路径的文本文件运行推理
python detect.py --weights yolov5s.pt --source list.txt
对列出流 URL 的文本文件运行推理
python detect.py --weights yolov5s.pt --source list.streams
使用 glob 模式对图像运行推理
python detect.py --weights yolov5s.pt --source 'path/to/.jpg'
对 YouTube 视频 URL 运行推理
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4'
对 RTSP、RTMP 或 HTTP 流运行推理
python detect.py --weights yolov5s.pt --source 'rtsp://example.com/media.mp4'
训练
以下命令演示了如何复现 YOLOv5 在 COCO 数据集上的结果。模型和数据集都会自动从最新的 YOLOv5 发布版本下载。YOLOv5n/s/m/l/x 的训练时间在单个 NVIDIA V100 GPU 上大约需要 1/2/4/6/8 天。使用多 GPU 训练可以显著减少训练时间。请使用硬件允许的最大 --batch-size,或使用 --batch-size -1 以启用 YOLOv5 AutoBatch。下面显示的批处理大小适用于 V100-16GB GPU。
bash
在 COCO 上训练 YOLOv5n 300 个周期
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml --batch-size 128
在 COCO 上训练 YOLOv5s 300 个周期
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5s.yaml --batch-size 64
在 COCO 上训练 YOLOv5m 300 个周期
python train.Top issues
#251TFLite, ONNX, CoreML, TensorRT Export407 comments · 2020-06-30#36Load YOLOv5 from PyTorch Hub ⭐320 comments · 2020-06-11#12Train Custom Data Tutorial ⭐214 comments · 2020-06-03#607Hyperparameter Evolution204 comments · 2020-08-02#475Multi-GPU Training 🌟111 comments · 2020-07-22#318Model Ensembling Tutorial108 comments · 2020-07-07#9627NVIDIA Jetson Nvidia Jetson Nano, Xavier NX, Orin Deployment tutorial78 comments · 2022-09-28#6998YOLOv5 (6.0/6.1) brief summary65 comments · 2022-03-16
Discussions
#13863Create custom dataset from pre-existing datasets2 comments · 2026-08-17#13722cv2.cuda_GpuMat()0 comments · 2026-03-16#13639Synthetic YOLO Dataset Generator0 comments · 2025-08-03#13636CUDNN ERROR in Blackwell GPU0 comments · 2025-07-30#13569Generating Precision, Recall, and [email protected] Metrics for Each Category in Faster R-CNN Using Detectron2 Object Detection Models0 comments · 2025-04-20#13557Problem with incorporating Python in visual studio code to employ YOLOv5 and practice object detection1 comments · 2025-04-08#13538How can I add more hyperparameters in YOLOv5 Genetic algorithm to evolve them?0 comments · 2025-03-20#13518font and color of the annotation box1 comments · 2025-02-24
Latest release
v7.0 - YOLOv5 SOTA Realtime Instance Segmentation v7.0 2022-11-22[assets]: https://github.com/ultralytics/yolov5/releases [previous]: https://github.com/ultralytics/yolov5/releases/tag/v6.2 [current]: https://github.com/ultralytics/yolov5/releases/tag/v7.0 [TTA]: https://github.com/ultralytics/yolov5/issues/303 Our new YOLOv5 v7.0 instance segmentation models are the fastest and most accurate in the world, beating all current SOTA benchmarks. We've made them super simple to train, validate and deploy. See full details in our Release Notes and visit our YOLOv5 Segmentation Colab Notebook for quickstart tutorials. Our primary