编译ONNX模型
本文是介绍如何使用Relay部署ONNX模型的入门教程。
首先,必须安装ONNX软件包。
一个快速的解决方案是安装protobuf编译器,然后
pip install onnx --user
或请参考官方网站。 https://github.com/onnx/onnx
import onnx
import numpy as np
import tvm
from tvm import te
import tvm.relay as relay
from tvm.contrib.download import download_testdata
加载预训练的ONNX模型
这里使用的示例超分辨率模型与onnx教程http://pytorch.org/tutorials/advanced/super_resolution_with_caffe2.html中的模型完全相同, 我们跳过了pytorch模型构建部分,并下载了保存的onnx模型
model_url="".join(
[
"https://gist.github.com/zhreshold/",
"bcda4716699ac97ea44f791c24310193/raw/",
"93672b029103648953c4e5ad3ac3aadf346a4cdc/",
"super_resolution_0.2.onnx",
]
)
model_path=download_testdata(model_url,"super_resolution.onnx",module="onn