本文是介绍如何使用Relay部署PyTorch模型的入门教程。
首先,应该安装PyTorch。还需要TorchVision,因为我们将其用作模型动物园。
一个快速的解决方案是通过pip安装
pip install torch==1.7.0
pip install torchvision==0.8.1
或请访问官方网站 https://pytorch.org/get-started/locally/
PyTorch版本应向后兼容,但应与正确的TorchVision版本一起使用。
目前,TVM支持PyTorch 1.7和1.4。其他版本可能不稳定。
import tvm
from tvm import relay
import numpy as np
from tvm.contrib.download import download_testdata
#pytorch imports
import torch
import torchvision
加载预训练的PyTorch模型