Skip to main content

Yet Another YOLOv5 and its Additional Runtime Stack

Project description

🔦 yolort - YOLOv5 Runtime Stack

CI testing PyPI version codecov Github Downloads Downloads PyPI Slack

What it is. Yet another implementation of Ultralytics's yolov5, and with modules refactoring to make it available in deployment backends such as libtorch, onnxruntime, tvm 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. You like the implementation of torchvision's faster-rcnn, retinanet or detr? You like yolov5? You love yolort!

YOLO inference demo

🆕 What's New

  • Support exporting to TorchScript model. Oct. 8, 2020.
  • Support inferring with LibTorch cpp interface. Oct. 10, 2020.
  • Add TorchScript cpp inference example. Nov. 4, 2020.
  • Refactor YOLO modules and support dynmaic batching inference. Nov. 16, 2020.
  • Support exporting to ONNX, and inferring with ONNXRuntime interface. Nov. 17, 2020.
  • Add graph visualization tools. Nov. 21, 2020.
  • Add TVM compile and inference notebooks. Feb. 5, 2021.

🛠️ 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.7.0+ and torchvision 0.8.1+

  • Installation via Pip

    Simple installation from PyPI

    pip install -U yolort
    

    Or from Source

    # clone yolort repository locally
    git clone https://github.com/zhiqwang/yolov5-rt-stack.git
    cd yolov5-rt-stack
    # 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/yolov5-rt-stack', 'yolov5s', pretrained=True)

Updating checkpoint from ultralytics/yolov5

The module state of yolort has some differences comparing to ultralytics/yolov5. We can load ultralytics's trained model checkpoint with minor changes, and we have converted ultralytics's release v3.1 and v4.0. For example, if you want to convert a yolov5s (release 4.0) model, you can just run the following script:

from yolort.utils import update_module_state_from_ultralytics

# Update module state from ultralytics
model = update_module_state_from_ultralytics(arch='yolov5s', version='v4.0')
# Save updated module
torch.save(model.state_dict(), 'yolov5s_updated.pt')

Inference on LibTorch backend 🚀

We provide a notebook to demonstrate how the model is transformed into torchscript. And we provide an C++ example of how to infer with the transformed torchscript model. For details see the GitHub Actions.

🎨 Model Graph Visualization

Now, yolort can draw the model graph directly, checkout our visualize-jit-models notebook to see how to use and visualize the model graph.

YOLO model visualize

🎓 Acknowledgement

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

🤗 Contributing

We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion. If you plan to contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us. BTW, leave a 🌟 if you liked it, this means a lot to us :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yolort-0.4.0.tar.gz (73.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yolort-0.4.0-py2.py3-none-any.whl (75.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file yolort-0.4.0.tar.gz.

File metadata

  • Download URL: yolort-0.4.0.tar.gz
  • Upload date:
  • Size: 73.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.4

File hashes

Hashes for yolort-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b6a7eb1758731d8d4143de5b50319618a03963997cc9b9b42b8eb685899e79a1
MD5 650b0ed1017ad8b8267ecb8e33324e78
BLAKE2b-256 0b920a6315ffd7f46903ca023223b3110ffd85384e4e3cf3b3333c2539842867

See more details on using hashes here.

File details

Details for the file yolort-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: yolort-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 75.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.2.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.4

File hashes

Hashes for yolort-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 120b1a653653727016c76c2822ff7b9bebf9d6232fa09e9239d0efb4dc74e3a8
MD5 dd931a7d03ab5eaedecd18293c71a3b1
BLAKE2b-256 bcc50283f05e8cbaa4cff537037af01d9afe8829b19d3eff212b7f31edb8f174

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page