# yolov5-rt-stack **Repository Path**: MrPaper/yolov5-rt-stack ## Basic Information - **Project Name**: yolov5-rt-stack - **Description**: yolort / yet another yolov5, with its runtime stack for libtorch, onnx, tvm, ncnn and specialized accelerators. - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-30 - **Last Updated**: 2021-08-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
**YOLOv5 Runtime Stack**
[](https://github.com/zhiqwang/yolov5-rt-stack/actions?query=workflow%3A%22CI+testing%22)
[](https://codecov.io/gh/zhiqwang/yolov5-rt-stack)
[](https://badge.fury.io/py/yolort)
[](https://pepy.tech/project/yolort)
[](https://img.shields.io/github/downloads/zhiqwang/yolov5-rt-stack/total?color=blue&label=Downloads&logo=github&logoColor=lightgrey)
[](https://join.slack.com/t/yolort/shared_invite/zt-mqwc7235-940aAh8IaKYeWclrJx10SA)
---
## 🆕 What's New
- Support exporting to `TorchScript` model. *Oct. 8, 2020*.
- Support inferring with `LibTorch` C++ interface. *Oct. 10, 2020*.
- Add `TorchScript` C++ inference example. *Nov. 4, 2020*.
- Refactor YOLO modules and support *dynamic shape/batch* 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](https://pytorch.org/get-started/locally/) to install PyTorch 1.7.0+ and torchvision 0.8.1+
- Installation via Pip
Simple installation from [PyPI](https://pypi.org/project/yolort/)
```shell
pip install -U yolort
```
Or from Source
```shell
# 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):
```shell
pip install -U 'git+https://github.com/ppwwyyxx/cocoapi.git#subdirectory=PythonAPI'
```
- To read a source of image(s) and detect its objects 🔥
```python
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:
```python
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](https://github.com/ultralytics/yolov5/releases/tag/v3.1) and [v4.0](https://github.com/ultralytics/yolov5/releases/tag/v4.0). For example, if you want to convert a `yolov5s` (release 4.0) model, you can just run the following script. You can also see our [how-to-align-with-ultralytics-yolov5](http://github.com/zhiqwang/yolov5-rt-stack/blob/master/notebooks/how-to-align-with-ultralytics-yolov5.ipynb) notebook for more details.
```python
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](notebooks/inference-pytorch-export-libtorch.ipynb) to demonstrate how the model is transformed into `torchscript`. And we provide an [C++ example](./deployment/libtorch) of how to infer with the transformed `torchscript` model. For details see the [GitHub Actions](.github/workflows/ci_test.yml).
## 🎨 Model Graph Visualization
Now, `yolort` can draw the model graph directly, checkout our [model-graph-visualization](notebooks/model-graph-visualization.ipynb) notebook to see how to use and visualize the model graph.