当前位置:网站首页>【TFLite, ONNX, CoreML, TensorRT Export】
【TFLite, ONNX, CoreML, TensorRT Export】
2022-07-05 11:42:00 【Network starry sky (LUOC)】
List of articles
This guide explains how to export a trained YOLOv5 model from PyTorch to ONNX and TorchScript formats. UPDATED 18 May 2022.
Before You Start
Clone repo and install requirements.txt in a Python>=3.7.0 environment, including PyTorch>=1.7. Models and datasets download automatically from the latest YOLOv5 release.
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
For TensorRT export example (requires GPU) see our Colab notebook appendix section. Open In Colab
Formats
YOLOv5 inference is officially supported in 11 formats:
ProTip: TensorRT may be up to 2-5X faster than PyTorch on GPU
ProTip: ONNX and OpenVINO may be up to 2-3X faster than PyTorch on CPU

Export a Trained YOLOv5 Model
This command exports a pretrained YOLOv5s model to TorchScript and ONNX formats. yolov5s.pt is the ‘small’ model, the second smallest model available. Other options are yolov5n.pt, yolov5m.pt, yolov5l.pt and yolov5x.pt, along with their P6 counterparts i.e. yolov5s6.pt or you own custom training checkpoint i.e. runs/exp/weights/best.pt. For details on all available models please see our README table.
python path/to/export.py --weights yolov5s.pt --include torchscript onnx
Output:
export: data=data/coco128.yaml, weights=yolov5s.pt, imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['torchscript', 'onnx']
YOLOv5 v6.0-241-gb17c125 torch 1.10.0 CPU
Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients
PyTorch: starting from yolov5s.pt (14.7 MB)
TorchScript: starting export with torch 1.10.0...
TorchScript: export success, saved as yolov5s.torchscript (29.4 MB)
ONNX: starting export with onnx 1.10.2...
ONNX: export success, saved as yolov5s.onnx (29.3 MB)
Export complete (7.63s)
Results saved to /Users/glennjocher/PycharmProjects/yolov5
Detect: python detect.py --weights yolov5s.onnx
PyTorch Hub: model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s.onnx')
Validate: python val.py --weights yolov5s.onnx
Visualize: https://netron.app
The 3 exported models will be saved alongside the original PyTorch model:
Netron Viewer is recommended for visualizing exported models:
Example Usage of exported models
export.py will show Usage examples for the last export format indicated. For example for ONNX:
detect.py runs inference on exported models:
python path/to/detect.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO
yolov5s.engine # TensorRT
yolov5s.mlmodel # CoreML (macOS only)
yolov5s_saved_model # TensorFlow SavedModel
yolov5s.pb # TensorFlow GraphDef
yolov5s.tflite # TensorFlow Lite
yolov5s_edgetpu.tflite # TensorFlow Edge TPU
val.pyruns validation on exported models:
python path/to/val.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO
yolov5s.engine # TensorRT
yolov5s.mlmodel # CoreML (macOS Only)
yolov5s_saved_model # TensorFlow SavedModel
yolov5s.pb # TensorFlow GraphDef
yolov5s.tflite # TensorFlow Lite
yolov5s_edgetpu.tflite # TensorFlow Edge TPU
OpenCV DNN C++
Examples of YOLOv5 OpenCV DNN C++ inference on exported ONNX models can be found at
https://github.com/Hexmagic/ONNX-yolov5/blob/master/src/test.cpp
https://github.com/doleron/yolov5-opencv-cpp-python
Environments
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
Google Colab and Kaggle notebooks with free GPU: Open In Colab Open In Kaggle
Google Cloud Deep Learning VM. See GCP Quickstart Guide
Amazon Deep Learning AMI. See AWS Quickstart Guide
Docker Image. See Docker Quickstart Guide Docker Pulls
Status
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
边栏推荐
- 12. (map data) cesium city building map
- C # implements WinForm DataGridView control to support overlay data binding
- 7.2 daily study 4
- 简单解决redis cluster中从节点读取不了数据(error) MOVED
- 7 大主题、9 位技术大咖!龙蜥大讲堂7月硬核直播预告抢先看,明天见
- Unity xlua monoproxy mono proxy class
- 如何让你的产品越贵越好卖
- AUTOCAD——遮罩命令、如何使用CAD对图纸进行局部放大
- 13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
- 《看完就懂系列》15个方法教你玩转字符串
猜你喜欢

AutoCAD -- mask command, how to use CAD to locally enlarge drawings

redis主从中的Master自动选举之Sentinel哨兵机制

龙蜥社区第九次运营委员会会议顺利召开
![[office] eight usages of if function in Excel](/img/ce/ea481ab947b25937a28ab5540ce323.png)
[office] eight usages of if function in Excel

MySQL 巨坑:update 更新慎用影响行数做判断!!!

idea设置打开文件窗口个数

MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!

12. (map data) cesium city building map

【云原生 | Kubernetes篇】Ingress案例实战(十三)

7.2 daily study 4
随机推荐
redis 集群模式原理
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
View all processes of multiple machines
紫光展锐全球首个5G R17 IoT NTN卫星物联网上星实测完成
AUTOCAD——遮罩命令、如何使用CAD对图纸进行局部放大
How to make your products as expensive as possible
如何通俗理解超级浏览器?可以用于哪些场景?有哪些品牌?
COMSOL -- three-dimensional graphics random drawing -- rotation
I used Kaitian platform to build an urban epidemic prevention policy inquiry system [Kaitian apaas battle]
COMSOL--建立几何模型---二维图形的建立
PHP中Array的hash函数实现
Open3D 欧式聚类
Prevent browser backward operation
ZCMU--1390: 队列问题(1)
Open3D 网格(曲面)赋色
Question and answer 45: application of performance probe monitoring principle node JS probe
POJ 3176-Cow Bowling(DP||记忆化搜索)
Cron expression (seven subexpressions)
[office] eight usages of if function in Excel
石油化工企业安全生产智能化管控系统平台建设思考和建议