把 onnx 格式的模型转换为 pytorch 格式

创建日期: 2024-08-12 17:29 | 作者: 风波 | 浏览次数: 21 | 分类: PyTorch

项目地址:https://github.com/ENOT-AutoDL/onnx2torch

1. 安装 onnx2torch

pip install onnx2torch -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

或者

conda install -c conda-forge onnx2torch

2. 转换模型

import onnx
import torch
from onnx2torch import convert

# Path to ONNX model
onnx_model_path = "/some/path/mobile_net_v2.onnx"
# You can pass the path to the onnx model to convert it or...
torch_model_1 = convert(onnx_model_path)

# Or you can load a regular onnx model and pass it to the converter
onnx_model = onnx.load(onnx_model_path)
torch_model_2 = convert(onnx_model)
21 浏览
11 爬虫
0 评论