yolort

zhiqwangGPL-3.0更新放缓

把 YOLOv5 模型部署到 TensorRT、LibTorch、ONNX Runtime、TVM、NCNN 等推理后端的运行时工具链,省去自己写适配代码。

yolort is a runtime stack for yolov5 on specialized accelerators such as tensorrt, libtorch, onnxruntime, tvm and ncnn.

v0.6.3发布于 2022-05-04 04:29 UTC730star149fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
pip install -U yolort
硬件要求按 README 说明

README 未说明具体显存要求;TensorRT 后端示例使用 CUDA 设备,ONNX Runtime 示例可在 CPU 上推理;未列出支持的 GPU 厂商与型号。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

YOLOv5 的运行时栈,把前后处理嵌入模型图,方便部署到多种推理后端

把 YOLOv5 模型部署到 TensorRT、LibTorch、ONNX Runtime、TVM、NCNN 等推理后端的运行时工具链,省去自己写适配代码。

核心能力

  • 采用动态 shape 机制支持动态尺寸和批量推理
  • 将 letterbox 预处理与 NMS 后处理嵌入模型计算图
  • 支持导出 TorchScript 并在 LibTorch C++ 中推理
  • 提供 ONNX Runtime 的 Python 与 C++ 推理接口
  • 支持导出 TensorRT engine 并用 Python/C++ 接口推理

容易踩的坑

需先按 PyTorch 官方说明安装 PyTorch 1.8.0+ 和 torchvision 0.9.0+;在 COCO 上做评估还需单独安装 pycocotools;TensorRT 与 ONNX Runtime 后端需要自行准备对应的 engine 或 onnx 模型文件。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.6.3
  1. v0.6.3TensorRT Windows Compatibility Patch Release最新正式版2022-05-04 · 2022-05-04 04:29 UTC

    This release is mainly for the compatibility of TensorRT C++ example (#389) and Python interface (#396) on Windows systems. In addition, this release introduces module helpers named is_module_available and requires_module to power the lazy inits of third-party libraries (#366, #367).

    Besides, we:

    • Fix circular reference of load_from_ultralytics (#369, #373, #374)
    • Add PyYAML to requirements (#363)
    • Add CLI tool for converting YOLO-format to MSCOCO (#375)
    • Upgrade dependencies (#372, #386, #398)
    • Update badges and fix docs (#388, #391)

    We're grateful for our community, which helps us improving yolort by submitting issues and PRs, and providing feedback and suggestions. The following persons have contributed patches for this release:

    @IamNaQi @mattpopovich @Yoh-Z @zhiqwang

  2. v0.6.2Compatibility updates for PyTorch 1.11.0 and AutoAnchor supports2022-03-12 · 2022-03-12 06:09 UTC
    查看更新说明

    This release is mainly compatibility updates for PyTorch 1.11.0 (#359) and to support loading the checkpoints trained with AutoAnchor mechanism in YOLOv5 (#285, #352).

    Besides, we

    • Move bias initializations from private methods to constructors (#351)
    • Upgrade PyTorch minimal version to 1.8.0 (#359)
    • Added support for Python 3.10 (only works with PyTorch 1.11) (#359)
    • Remove lightning strong dependencies (#355, #358)
    • Update tutorials with Visualizer (#354)
    • Small grammar and spelling fixes (#357)

    We're grateful for our community, which helps us improving yolort by submitting issues and PRs, and providing feedback and suggestions. The following persons have contributed patches for this release:

    @mattpopovich @zhiqwang

    Full Changelog: https://github.com/zhiqwang/yolov5-rt-stack/compare/v0.6.1...v0.6.2

  3. v0.6.1Connecting with TorchVision's model banks2022-03-08 · 2022-03-08 15:32 UTC
    查看更新说明

    This release adds an example to showcase how to use the model banks provided by TorchVision to build a new YOLOv5 model, introduces Visualizer to display the predictions and fixes an incompatible bug in YOLOv5 Detect Layer.

    Highlights

    Build a new YOLOv5 model via TorchVision's model banks

    We add an example to showcase how to construct a YOLOv5-Lite model with TorchVision's pre-trained MobileNetV3-Small FPN as the backbone.

    import torch
    from yolort.models.yolo_lite import yolov5_mobilenet_v3_small_fpn
    
    model = yolov5_mobilenet_v3_small_fpn()
    model = model.eval()
    
    images = torch.rand(4, 3, 640, 640)
    out = model(images)
    
    • Use C3 following the model specification of YOLOv5 (#343)
    • Construct YOLOv5 models with TorchVision MobileNetV3 backbone (#342)

    Introduce a new visualization interface

    from torchvision.io import read_image
    from yolort.models import yolov5n6
    from yolort.utils import Visualizer
    
    model = yolov5n6(pretrained=True, score_thresh=0.45)
    model = model.eval()
    img_path = "bus.jpg"
    preds = model.predict(img_path)
    
    metalabels_path = "coco.names"
    image = read_image(img_path)
    v = Visualizer(image, metalabels=metalabels_path)
    v.draw_instance_predictions(preds[0])
    v.imshow(scale=0.5)
    
    • Add Visualizer for visualization (#341)

    Bugfixes

    • Fix YOLOv5 AnchorGenerator compatibility (#345)
    • Add missing version param in export_tensorrt (#335)

    Code Quality

    • Update Visualizer in docs and PR Recommendations (#346)
    • Bump versions on GH Action (#344, #338, #337)

    Contributors

    We're grateful for our community, which helps us improving yolort by submitting issues and PRs, and providing feedback and suggestions. The following persons have contributed patches for this release:

    @Luwill6, @zhiqwang

    Full Changelog: https://github.com/zhiqwang/yolov5-rt-stack/compare/v0.6.0...v0.6.1

  4. v0.6.0TensorRT deployment Support, Pre-Processing alignment and more2022-02-19 · 2022-02-19 10:08 UTC
    查看更新说明

    This release provides TensorRT deployment support both for Python and C++ interface and supports pre-processing alignment with the official yolov5.

    Highlights

    Use yolort to deploy YOLOv5 on TensorRT

    Unlike other pipelines that deal with YOLOv5 on TensorRT, we embed the whole post-processing into the serialized engine with TensorRT's EfficientNMS_TRT plugin. This pipeline could simplify deployment and gain in speed due to TensorRT's efficient implementation of this plugin. Check out this tutorial detailing yolort's model conversion and use cases. Here is a Python pipeline to deploy YOLOv5 on TensorRT.

    import torch
    from yolort.runtime import PredictorTRT
    
    # Load the serialized TensorRT engine
    engine_path = "yolov5n6.engine"
    device = torch.device("cuda")
    y_runtime = PredictorTRT(engine_path, device=device)
    
    # Perform inference on an image file
    predictions = y_runtime.predict("bus.jpg")
    
    • Support exporting yolort to TensorRT serialized engine (#238, #242, #243, #252, #254, #263, #275, #288, #311, #312, #326)
    • Add TensorRT Python inference pipeline (#251, #253, #256, #259, #283, #290, #307, #309)
    • Add TensorRT C++ inference example (#245, #257, #258, #261, #262, #305, #321, #323, #324)

    Alignment with the official yolov5 Pre-Processing

    Pre-processing misalignment has been an obstacle to getting yolort to land, and we've fixed that in this release.

    • Fix the consistency of pre-processing with yolov5 (#293)
    • Support fixed shape inference in pre-processing (#301)
    • Fix pre-processing for TVM VM inference (#302)

    Backwards Incompatible Changes

    • Rename relaying to relay (#313)
    • Move Lightning wrapper into trainer (#314)
    • Deprecate the methods run_on_image function in PredictorORT (#327)

    Improvement

    • Support loading the latest version of yolov5 (#235)
    • Formal documentation support (#224, #225, #292)
    • Cleanup AnchorGenerator and PostProcess (#203)
    • Revert SPPF to SPP for downstream compatible (#240)
    • Support custom image size when exporting ONNX models (#250, #264, #269)
    • Upgrade with latest PyTorch version in GH Actions (#255)
    • Update PyTorch to 1.10 in TVM relay VM tutorial (#287)
    • Enhance PredictorORT to adapt to more scenarios (#319, #320, #327)
    • Support publishing 🐍 to PyPI.org 📦 with GH Actions (#229, #241, #306, #328, #329)

    Bugfixes

    • Small fixes to CONTRIBUTING guide (#218)
    • Fix type casting in ONNX Runtime C++ example (#221)
    • Fix TorchScript exporting for custom checkpoints (#267)
    • Fix non-agnostic parameter in tutorial (#284)
    • Fix a bug and document RandomZoomOut (#289)
    • Compatible with Windows for LibTorch deployment (#303)

    Documentation improvements

    • Add comparison docs for yolov5 & yolort (#300)
    • Update Docs and Readme (#223, #299, #304, #308, #315)
    • Add Fidan and Shiquan as co-authors for great contributions (#231, #258)

    Code Quality

    • Update to .clang-format (#222)
    • Enable pip cache dependencies in GH Actions (#226)
    • Move CONTRIBUTING and CODE_OF_CONDUCT into .github (#228)
    • Cleanup unit-test (#246)
    • Fixed some spelling/typos (#276)
    • Set OpenCV as optional (#286)
    • [pre-commit.ci] pre-commit autoupdate (#244, #249, #260, #270)
    • Install yolort in GH Actions (#294)
    • Replaced to_tensor() with pil_to_tensor() + convert_image_dtype() (#298)
    • Remove CLI tools for detection and training temporarily (#325)

    Contributors

    We're grateful for our community, which helps us improving yolort by submitting issues and PRs, and providing feedback and suggestions. The following persons have contributed patches for this release:

    @datumbox @lzmisscc @mattpopovich @ncnnnnn @ShiquanYu @triple-Mu @yang-gis @zhiqwang @2428513107

    Special thanks to @ShiquanYu for his great contributions on TensorRT C++ example!

  5. v0.5.2Support upstream yolov5 v6.0 models2021-10-27 · 2021-10-27 09:02 UTC
    查看更新说明

    This release mainly supports upstream YOLOv5 v6.0 models.

    Highlights

    We set the model to r6.0 by default, and rest of the usage interface is the same as before.

    from yolort.models import yolov5n6
    
    # Load model
    model = yolov5n6(upstream_version="r6.0", pretrained=True, score_thresh=0.45)
    model.eval()
    
    # Perform inference on an image file
    predictions = model.predict("bus.jpg")
    # Perform inference on a list of image files
    predictions = model.predict(["bus.jpg", "zidane.jpg"])
    

    New Features

    • Fully support upstream YOLOv5 v6.0 models (#194, #195, #196, #199, #204, #206, #213, #215) Thanks @deepage
    • Support PyTorch 1.10 (#207)
    • Support skipping preprocess when exporting ONNX (#193)

    Backwards Incompatible Changes

    • Set main as the base branch (#200)
    • Rename _yolov5_darknet_pan to build_model (#198)

    Improvement

    • Use torch.jit.trace in unit-test for easier use in downstream (#205) Thanks @nihui
    • Update model graph visualization images (#212)
    • [pre-commit.ci] pre-commit autoupdate (#191, #197)

    Bugfixes

    • Fix non-renderable images on PyPI (#209, #210)
    • Fix the anchor configuration mechanism (#201, #202)
    • Small fixes to the docstrings (#208)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    YOLOv5 Runtime Stack


    Documentation • Installation Instructions • Deployment • Contributing • Reporting Issues


    Python Version PyPI version PyPI downloads Github downloads Slack PRs Welcome

    CI testing Build & deploy docs pre-commit.ci status codecov


    🤗 Introduction

    What it is. Yet another implementation of Ultralytics's YOLOv5. yolort aims to make the training and inference of the object detection task integrate more seamlessly together. yolort now adopts the same model structure as the official YOLOv5. The significant difference is that we adopt the dynamic shape mechanism, and within this, we can embed both pre-processing (letterbox) and post-processing (nms) into the model graph, which simplifies the deployment strategy. In this sense, yolort makes it possible to deploy the object detection more easily and friendly on LibTorch, ONNX Runtime, TVM, TensorRT and so on.

    About the code. Follow the design principle of detr:

    object detection should not be more difficult than classification, and should not require complex libraries for training and inference.

    yolort is very simple to implement and experiment with. Do you like the implementation of torchvision's faster-rcnn, retinanet or detr? Do you like yolov5? You'll love yolort!

    🆕 What's New

    • Dec. 27, 2021. Add TensorRT C++ interface example. Thanks to Shiquan.
    • Dec. 25, 2021. Support exporting to TensorRT, and inferencing with TensorRT Python interface.
    • Sep. 24, 2021. Add ONNX Runtime C++ interface example. Thanks to Fidan.
    • Feb. 5, 2021. Add TVM compile and inference notebooks.
    • Nov. 21, 2020. Add graph visualization tools.
    • Nov. 17, 2020. Support exporting to ONNX, and inferencing with ONNX Runtime Python interface.
    • Nov. 16, 2020. Refactor YOLO modules and support dynamic shape/batch inference.
    • Nov. 4, 2020. Add LibTorch C++ inference example.
    • Oct. 8, 2020. Support exporting to TorchScript model.

    🛠️ Usage

    There are no extra compiled components in yolort and package dependencies are minimal, so the code is very simple to use.

    Installation and Inference Examples

    • Above all, follow the official instructions to install PyTorch 1.8.0+ and torchvision 0.9.0+

    • Installation via pip

      Simple installation from PyPI

      pip install -U yolort
      

      Or from Source

      # clone yolort repository locally
      git clone https://github.com/zhiqwang/yolort.git
      cd yolort
      # install in editable mode
      pip install -e .
      
    • Install pycocotools (for evaluation on COCO):

      pip install -U 'git+https://github.com/ppwwyyxx/cocoapi.git#subdirectory=PythonAPI'
      
    • To read a source of image(s) and detect its objects 🔥

      from yolort.models import yolov5s
      
      # Load model
      model = yolov5s(pretrained=True, score_thresh=0.45)
      model.eval()
      
      # Perform inference on an image file
      predictions = model.predict("bus.jpg")
      # Perform inference on a list of image files
      predictions = model.predict(["bus.jpg", "zidane.jpg"])
      

    Loading via torch.hub

    The models are also available via torch hub, to load yolov5s with pretrained weights simply do:

    model = torch.hub.load("zhiqwang/yolort:main", "yolov5s", pretrained=True)
    

    Loading checkpoint from official yolov5

    The following is the interface for loading the checkpoint weights trained with ultralytics/yolov5. Please see our documents on what we share and how we differ from yolov5 for more details.

    from yolort.models import YOLOv5
    
    # Download checkpoint from https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5s.pt
    ckpt_path_from_ultralytics = "yolov5s.pt"
    model = YOLOv5.load_from_yolov5(ckpt_path_from_ultralytics, score_thresh=0.25)
    
    model.eval()
    img_path = "test/assets/bus.jpg"
    predictions = model.predict(img_path)
    

    🚀 Deployment

    Inference on LibTorch backend

    We provide a tutorial to demonstrate how the model is converted into torchscript. And we provide a C++ example of how to do inference with the serialized torchscript model.

    Inference on ONNX Runtime backend

    We provide a pipeline for deploying yolort with ONNX Runtime.

    from yolort.runtime import PredictorORT
    
    # Load the serialized ONNX model
    engine_path = "yolov5n6.onnx"
    y_runtime = PredictorORT(engine_path, device="cpu")
    
    # Perform inference on an image file
    predictions = y_runtime.predict("bus.jpg")
    

    Please check out this tutorial to use yolort's ONNX model conversion and ONNX Runtime inferencing. And you can use the example for ONNX Runtime C++ interface.

    Inference on TensorRT backend

    The pipeline for TensorRT deployment is also very easy to use.

    import torch
    from yolort.runtime import PredictorTRT
    
    # Load the serialized TensorRT engine
    engine_path = "yolov5n6.engine"
    device = torch.device("cuda")
    y_runtime = PredictorTRT(engine_path, device=device)
    
    # Perform inference on an image file
    predictions = y_runtime.predict("bus.jpg")
    

    Besides, we provide a tutorial detailing yolort's model conversion to TensorRT and the use of the Python interface. Please check this example if you want to use the C++ interface.

    🎨 Model Graph Visualization

    Now, yolort can draw the model graph directly, checkout our tutorial to see how to use and visualize the model graph.

    👋 Contributing

    We love your input! Please see our Contributing Guide to get started and for how to help out. Thank you to all our contributors! If you like this project please consider ⭐ this repo, as it is the simplest way to support us.

    Contributors

    📖 Citing yolort

    If you use yolort in your publication, please cite it by using the following BibTeX entry.

    @Misc{yolort2021,
      author =       {Zhiqiang Wang and Song Lin and Shiquan Yu and Wei Zeng and Fidan Kharrasov},
      title =        {YOLORT: A runtime stack for object detection on specialized accelerators},
      howpublished = {\url{https://github.com/zhiqwang/yolort}},
      year =         {2021}
    }
    

    🎓 Acknowledgement

    • The implementation of yolov5 borrow the code from ultralytics.
    • This repo borrows the architecture design and part of the code from torchvision.