RepositoryPythonCNChina
zhiqwang

zhiqwang/yolort

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

730stars
149forks
28issues
4views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: torchscript

#1 Repository of the month

1
TINIX TRENDING·Topic: yolov5

#1 Repository of the month

1
TINIX TRENDING·Topic: tvm

#1 Repository of the month

🤗 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!

YOLO inference demo

🆕 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.

YOLO model visualize

👋 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.

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
ultralytics/yolov5

Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.

58.3k
Nov 23, 2026
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026
RepositoryPython
vllm-project/vllm

A high-throughput and memory-efficient inference and serving engine for LLMs

98.0k
Dec 2, 2026
RepositoryPython
deepspeedai/DeepSpeed

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

43.4k
Dec 1, 2026
RepositoryPython
snakers4/silero-vad

Silero VAD: pre-trained enterprise-grade Voice Activity Detector

10.8k
Nov 26, 2026
RepositoryPython
hukaixuan19970627/yolov5_obb

yolov5 + csl_label.(Oriented Object Detection)(Rotation Detection)(Rotated BBox)基于yolov5的旋转目标检测

2.0k
Oct 13, 2023
RepositoryPython
Comfy-Org/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

149.6k
Dec 2, 2026
Modelsentence-similarity
BAAI/bge-m3

For more details please refer to our github repo: https://github.com/FlagOpen/FlagEmbedding BGE-M3 (paper(https://arxiv.org/pdf/2402.03216.pdf), code(https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/BGEM3)) In this project, we intr...

♥0
37.8M
Jul 3, 2024
Modeltext-ranking
cross-encoder/ms-marco-MiniLM-L6-v2

Cross-Encoder for MS Marco This model was trained on the MS Marco Passage Ranking(https://github.com/microsoft/MSMARCO-Passage-Ranking) task. The model can be used for Information Retrieval: Given a query, encode the query will all possible passages...

♥0
52.2M
Aug 9, 2026