开始使用

Ultralytics YOLOv5

概述#

YOLOv5u 是 Ultralytics YOLOv5 的更新版本,用于目标检测。YOLOv5u 基于 Ultralytics 开发的 YOLOv5模型架构,并集成了最初在 YOLOv8模型中引入的无锚框、无目标性分离头。这项改动改善了精度与速度之间的权衡,使 YOLOv5u 成为研究和实际应用中的高效选择。

YOLOv5 目标检测模型架构与性能

使用原始 YOLOv5 仓库训练的模型与 Ultralytics 库不兼容

Ultralytics 提供 YOLOv5 模型的无锚框变体。使用 ultralytics/yolov5 仓库训练的模型无法通过 ultralytics/ultralytics 库加载。要在此处使用 YOLOv5,请基于 Ultralytics YOLOv5u 检查点训练新模型(例如 yolov5su.pt)。

在 Ultralytics Platform 上试用

直接在 Ultralytics Platform 上探索并运行 YOLOv5 模型。

Input
Upload an image or select an example to test yolov5nu. Predict Docs
Live Demo

Drop an image here

or click to browse

Supports JPEG, PNG, WebP, AVIF, HEIC, JP2, TIFF, BMP & more (max 10MB)

Confidence
0.25
IoU
0.50
Image Size
640
Prediction results will appear here.

主要功能#

  • 无锚框分离式 Ultralytics 检测头: 传统目标检测模型依赖预定义的锚框来预测目标位置。YOLOv5u 则使用无锚框分离式 Ultralytics 检测头,提供更灵活的检测机制,并提升模型在各种场景下的性能。

  • 优化精度与速度的权衡: YOLOv5u 平衡了速度和精度,能够以有竞争力的精度实现实时检测。这对于要求快速响应的应用很有价值,例如自动驾驶汽车、机器人和实时视频分析。

  • 多种预训练模型: YOLOv5u 提供 5 种尺寸(n、s、m、l、x)的 COCO 预训练模型,输入分辨率为 640;此外还提供输入分辨率为 1280 的 P6 变体,你可以根据硬件选择合适的速度与精度组合,并在自己的数据上微调。

支持的任务和模式#

YOLOv5u 模型提供多种预训练权重,支持目标检测以及从开发到部署所需的所有模式。

模型类型预训练权重任务训练验证推理导出
YOLOv5uyolov5nu, yolov5su, yolov5mu, yolov5lu, yolov5xu, yolov5n6u, yolov5s6u, yolov5m6u, yolov5l6u, yolov5x6u目标检测✅✅✅✅

此表总结了 YOLOv5u 各模型变体及其对训练、验证、推理和导出模式的支持情况。

性能指标#

性能

这些模型在 COCO 上训练,包含 80 个预训练类别;使用示例请参阅检测文档。

模型YAML尺寸
(像素)
mAPval50-95速度
CPU ONNX
(毫秒)
速度
A100 TensorRT
(毫秒)
参数
(M)
FLOPs
(B)
yolov5nu.ptyolov5n.yaml64034.373.61.062.67.7
yolov5su.ptyolov5s.yaml64043.0120.71.279.124.0
yolov5mu.ptyolov5m.yaml64049.0233.91.8625.164.2
yolov5lu.ptyolov5l.yaml64052.2408.42.5053.2135.0
yolov5xu.ptyolov5x.yaml64053.2763.23.8197.2246.4
yolov5n6u.ptyolov5n6.yaml128042.1211.01.834.331.3
yolov5s6u.ptyolov5s6.yaml128048.6422.62.3415.397.6
yolov5m6u.ptyolov5m6.yaml128053.6810.94.3641.2261.3
yolov5l6u.ptyolov5l6.yaml128055.71470.95.4786.1549.4
yolov5x6u.ptyolov5x6.yaml128056.82436.58.98155.51002.8

使用示例#

此示例提供简单的 YOLOv5 训练和推理示例。

示例

PyTorch 预训练的 *.pt 模型以及配置 *.yaml 文件都可以传递给 YOLO() 类,从而在 Python 中创建模型实例:

from ultralytics import YOLO

# 加载使用 COCO 预训练的 YOLOv5nu 模型
model = YOLO("yolov5nu.pt")

# 显示模型信息(可选)
model.info()

# 使用 COCO8 示例数据集训练模型 100 个 epoch
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

# 使用 YOLOv5nu 模型对“bus.jpg”图像运行推理
results = model("path/to/bus.jpg")

引用与致谢#

Ultralytics YOLOv5 论文

由于模型快速演进,Ultralytics 尚未为 YOLOv5 发表正式研究论文。我们专注于推进技术发展并降低使用门槛,而不是编写静态文档。要获取 YOLO 架构、功能和用法的最新信息,请参阅我们的 GitHub 仓库和文档。

如果你在研究中使用 YOLOv5 或 YOLOv5u,请按以下方式引用 Ultralytics YOLOv5 仓库:

引用
@software{yolov5,
  title = {Ultralytics YOLOv5},
  author = {Glenn Jocher},
  year = {2020},
  version = {7.0},
  license = {AGPL-3.0},
  url = {https://github.com/ultralytics/yolov5},
  doi = {10.5281/zenodo.3908559},
  orcid = {0000-0001-5950-6979}
}

请注意,YOLOv5 模型采用 AGPL-3.0 和企业版许可证提供。

常见问题#

  • Ultralytics YOLOv5u 是 YOLOv5 的更新版本,集成了无锚框、无目标性分数的分离式头部,提升了实时目标检测任务中准确率与速度之间的权衡。与传统 YOLOv5 不同,YOLOv5u 采用无锚框检测机制,因此在各种场景中更加灵活、适应性更强。

  • YOLOv5u 中的无锚框 Ultralytics 头部通过消除对预定义锚框的依赖来提升目标检测性能。这带来了更加灵活且适应性更强的检测机制,能够更高效地处理各种尺寸和形状的目标。这一改进直接促成了准确率与速度之间的平衡,使 YOLOv5u 适用于实时应用。你可以在主要特性部分详细了解其架构。

  • YOLOv5u 模型的性能指标因所用平台和硬件而异。例如,YOLOv5nu 模型在 COCO 数据集上达到 34.3 mAP,在 CPU(ONNX)上的速度为 73.6 毫秒,在 A100 TensorRT 上为 1.06 毫秒。每种 YOLOv5u 模型的详细指标,包括 CPU ONNX 和 A100 TensorRT 速度,均列于性能指标部分。

  • 你可以通过加载预训练模型并使用自己的数据集运行训练命令来训练 YOLOv5u 模型。下面是一个简要示例:

    示例
    from ultralytics import YOLO
    
    # 加载使用 COCO 预训练的 YOLOv5nu 模型
    model = YOLO("yolov5nu.pt")
    
    # 显示模型信息(可选)
    model.info()
    
    # 使用 COCO8 示例数据集训练模型 100 个 epoch
    results = model.train(data="coco8.yaml", epochs=100, imgsz=640)

    如需更详细的说明,请访问用法示例部分。

评论30

提出问题、分享结果,或帮助其他人。

  1. PriyaRanjanReddyGitHub

    Hi can we use yolov5nu.pt for training on my own dataset and then use the trained model for commercial use where I can build an application over it

    1. Glenn JocherUltralytics

      @PriyaRanjanReddy yes, you can use YOLOv5nu.pt for training on your dataset. For commercial use, you'll need an Ultralytics Enterprise License, which allows proprietary deployment without AGPL-3.0's open-source requirements. Visit https://ultralytics.com/license for licensing details.

    2. Glenn JocherUltralytics(已编辑)

      @PriyaRanjanReddy Ultralytics models, including YOLOv5u, YOLOv8, YOLO11 and YOLO26, are released under AGPL-3.0. You can use them commercially if your application complies with AGPL-3.0 (including open-sourcing it); otherwise you need an Ultralytics Enterprise License. Pricing varies based on your project's needs, so please visit our licensing page to discuss details.

  2. donia444GitHub

    hey ,i am trying to train yolov5nu on a custom dataset that is specifically for drone detection ,every time i train using this model ,i notice that my model overfits and gives a very very high unreal accuracy , but when i train on a different model like yolov5n that problem seem to not be found ,any idea why is that happening

    1. Glenn JocherUltralytics

      @donia444 it seems that your YOLOv5nu model might be overfitting due to its more complex architecture compared to YOLOv5n, which is simpler and might generalize better on your dataset. Consider using techniques like data augmentation, dropout, or early stopping to mitigate overfitting. You can find additional strategies in the Ultralytics documentation to help address this issue.

  3. MadhavKrishna1GitHub

    1.Does the kaggle dataset have a label file also? 2.How can i fine tune the model ,is there any built in library through which i could fine tune it.

    On Sun, 22 Sept 2024 at 13:12, Glenn Jocher @.***> wrote:

    @MadhavKrishna1 https://github.com/MadhavKrishna1 yOLOv5 models are indeed trained on the full COCO dataset, which includes 80 classes. For additional datasets similar to COCO, you might explore open-source repositories or platforms like Kaggle. Fine-tuning with your specific images should enhance performance on your target data.

    — Reply to this email directly, view it on GitHub https://github.com/orgs/ultralytics/discussions/10054#discussioncomment-10716632, or unsubscribe https://github.com/notifications/unsubscribe-auth/BCVBHHUR2WRPYUK46RYYFGTZXZYHRAVCNFSM6AAAAABGG3IMDCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANZRGY3DGMQ . You are receiving this because you were mentioned.Message ID: @.*** com>

    1. Glenn JocherUltralytics

      @MadhavKrishna1 1. Yes, Kaggle datasets often include label files, but it's best to check the specific dataset details on Kaggle. 2. You can fine-tune the model using the Ultralytics YOLO Python API, which provides built-in support for training and fine-tuning.

  4. MadhavKrishna1GitHub

    I would like to know about the training process of the YOLOv5 model. Specifically, is it trained on the entire COCO dataset? I am planning to fine-tune a downloaded YOLOv5 model using additional images that are similar to those in the COCO dataset. These images have 80 classes and similar sizes to those in COCO Could you provide guidance on finding this additional dataset?

    Thank you!

    1. Glenn JocherUltralytics

      @MadhavKrishna1 yOLOv5 models are indeed trained on the full COCO dataset, which includes 80 classes. For additional datasets similar to COCO, you might explore open-source repositories or platforms like Kaggle. Fine-tuning with your specific images should enhance performance on your target data.

    1. Glenn JocherUltralytics(已编辑)

      @Abhinay-Sadineni yes, yolov5su.pt is an Ultralytics YOLOv5u checkpoint and loads directly with the YOLO class from the ultralytics package, so ensure you have the latest version installed. Checkpoints trained with the original ultralytics/yolov5 repo are the ones that cannot be loaded this way. For more details, visit the YOLOv5 documentation.

    2. chef-SAbhinayGitHub

      is this yolov5su.pt(yolov5 model) compatible with latest ultralytics package ?

      my experiment setup doesn't allow the autoinstall 'ultralytics.yolo' (i mean external traffic is blocked)

      @glenn-jocher

      will the latest package also issue autoinstall warning?

    3. Glenn JocherUltralytics

      To use yolov5su.pt with the latest Ultralytics package, ensure you have the latest version installed. If your setup blocks external traffic, you can manually download the model and dependencies. The autoinstall warning may still appear if dependencies are missing. For a seamless experience, consider using the model with the Ultralytics YOLO class after ensuring all dependencies are locally available.

    4. kanagarajan0709GitHub

      I built a custom dataset from Ultralytics Hub platform using Yolov5su model type and downloaded the trained model. When I tried to load getting this error : "An error occurred: 'Detect' object has no attribute 'grid'. "

      This is how I load the model : yolov5path - points to latest yolov5 git repo. model path - refers to YOLOv5su model trained using Ultralytics Hub.

      yolo_model = torch.hub.load(yolov5path, 'custom', force_reload=True, path=model_path, source='local')

      YOLOv5 v7.0-338-gff063284 Python-3.12.4 torch-2.3.1+cpu CPU

      YOLOv5s summary (fused): 193 layers, 9,114,632 parameters, 0 gradients, 23.8 GFLOPs Adding AutoShape... An error occurred: 'Detect' object has no attribute 'grid'.

    5. Glenn JocherUltralytics(已编辑)

      @kanagarajan0709 yolov5su.pt is an Ultralytics YOLOv5u checkpoint and loads with the YOLO class from the latest ultralytics package. The "Detect object has no attribute 'grid'" error appears when a checkpoint from the original ultralytics/yolov5 repo is loaded with ultralytics, or when yolov5su.pt is loaded with the old yolov5 repo code. Load yolov5su.pt with from ultralytics import YOLO, and use the yolov5 repo only for checkpoints trained there. See the YOLOv5 documentation.

    6. kanagarajan0709GitHub(已编辑)

      To resolve this, please ensure you are using the correct version of the YOLOv5 repository that supports the yolov5su.pt model. If the issue persists, consider using the torch.hub.load method with the appropriate YOLOv5 version.

      Yes , that's what I would be interested to know about. Could you please let me know which Yolov5 git hub repo that supports loading of yolov5su model.

      I am currently on latest git version of this - https://github.com/ultralytics/yolov5. Last commit e8a30cf820b273afbbf1c73a3f1088471a84fade (HEAD -> master, origin/master, origin/HEAD) Author: Glenn Jocher glenn.jocher@ultralytics.com

      Also I did use torch.hub.load method to load the model as below , yolo_model = torch.hub.load(yolov5path, 'custom', force_reload=True, path=model_path, source='local')

    7. Glenn JocherUltralytics(已编辑)

      To load yolov5su.pt, use the YOLO class from the latest ultralytics package (YOLO("yolov5su.pt")). It is an Ultralytics YOLOv5u checkpoint and is not meant for the ultralytics/yolov5 repo, which loads checkpoints trained there.

  5. Halafz7GitHub

    Good Content! I want to ask something. Is it possible to use yolov5u for Classification purposes?

    1. Paula DerrengerUltralytics(已编辑)

      @Halafz7 thank you for your kind words! 😊

      YOLOv5u is designed for object detection. For classification, use a classification model such as YOLO26, which supports it directly.

      Python Example
      from ultralytics import YOLO
      
      # Load a pretrained YOLO26 classification model
      model = YOLO("yolo26n-cls.pt")
      
      # Run inference on an image
      results = model("path/to/image.jpg")
      
      # Display the results
      results[0].show()
      CLI Example
      # Run inference with a YOLO26 classification model
      yolo predict model=yolo26n-cls.pt source=path/to/image.jpg

      For more details, see the Classify docs.

      If you have any more questions or need further assistance, feel free to ask! 🚀

  6. MikolajBaranskiGitHub

    My questions (as of 12th April 2024) is whether there is any documentation regarding the Yolov5u model. The description on this page states that the Yolov5u incorporates the objectness-free split head into the Yolov5 architecture. Is there any further documentation on this model? The Yolov5 GitHub doesn't seem to present this model anywhere. While the page of v7.0 update only describes the introduction of segmentation. Is there any resource going into more detail into this specific release of the model?

    I see there is also documentation regarding the architecture of the Yolov5 v6.1/6.0 model (link below for reference). Is the Yolov5u an adaptations of that architecture? If so which part is changed?

    Github: https://github.com/ultralytics/yolov5 Architecture: https://docs.ultralytics.com/yolov5/tutorials/architecture_description/

    1. Paula DerrengerUltralytics

      Hey there! 😊 It looks like you're exploring the details of our YOLOv5u model. Indeed, YOLOv5u builds upon the YOLOv5 architecture, especially by incorporating an anchor-free, objectness-free split head, a feature inspired by advancements in YOLOv8. This enhancement is aimed at refining the model's ability to detect objects with a better accuracy-speed tradeoff.

      Although it seems there might not be detailed standalone documentation on the YOLOv5u model in the Ultralytics GitHub repo, the key updates and features you’re interested in are described in our Ultralytics YOLOv5 Overview. This page highlights the integration of the anchor-free split head into the model and its impact on performance and adaptability in various scenarios.

      Regarding your question on the architecture adaptation, yes, YOLOv5u adapts the YOLOv5 v6.1/6.0 architecture. The primary change lies in the detection head of the model, which has moved towards an anchor-free, objectness-free approach. This move enhances flexibility and detection efficiency, especially in complex scenarios where predefined anchor boxes might limit the detection capabilities.

      If you're looking for more technical specifics or examples, I'd recommend diving into the architecture description you mentioned. While it focuses on an earlier version, the core architectural principles remain relevant, with the YOLOv5u modifications centered around the detection head for improved performance.

      For direct experimentation or further exploration of the YOLOv5u's unique features, playing with the pre-trained models and reviewing their performance metrics might also offer valuable insights.

      I hope this clarifies your queries! If you have more questions or need further assistance, feel free to ask. Happy detecting! 🚀

    2. MikolajBaranskiGitHub

      Thank you that is a very helpful answer! Just to make a final clarification. I am using the YOLOv5u in my Masters Thesis and I would like to appropriately record the model I have used. For the YOLOv5xu.pt (the pretrained model), should I refer to it as the extra large version of the YOLOv5u v1.0, or is it the YOLOv5 v7.0, or is there some other versioning that would correctly identify this specific release of the model?

    3. Paula DerrengerUltralytics

      Hey, thanks for reaching out with your question! 😊

      For your Masters Thesis, when documenting the model, it's best to refer to it as YOLOv5u, specifying the version as YOLOv5 v7.0 if that's the version you're utilizing, along with the specific variant you're using, for instance, yolov5xu.pt for the extra-large model. It's key to mention both the overall version (v7.0, as an example) and the specific model variant (xu) to provide clear context and specificity about the architecture and features employed in your work.

      Here's how you could cite it:

      "I utilized the YOLOv5u extra-large variant (yolov5xu.pt) from the YOLOv5 v7.0 release for object detection tasks in my project."

      This approach ensures that your documentation is clear, precise, and tracks back to the correct version of the model relevant to your study.

      Hope this helps, and all the best with your thesis! 🚀 If there's anything more you need, feel free to ask.