在onnx推理onnxruntime出现警告问题解决

在用onnx进行推理模型时出现以下的警告:

 [W:onnxruntime:, graph.cc:1074 Graph] Initializer res_5_block1_conv_dw_relu_gamma appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.

 

解决办法:

方法一:

升级最新版的onnx,然后重新把pytorch模型转换为onnx模型。

 

方法二:

(1)下载 remove_initializer_from_input.py文件

(2)执行命令:

python remove_initializer_from_input.py --input mobilenet.onnx --output mobilenet_output.onnx

 

 

 

 

ONNXRuntime是微软推出的一款优秀的推理框架,它支持多种后端包括CPU、GPU、TensorRT和DML等,可以方便地运行ONNX模型。用户可以使用C、Python、Java等多种编程语言进行编写,并且提供了简单易用的API,使得使用者可以方便地进行模型推理。如果你想使用Python进行ONNXRuntime模型推理,可以按照以下步骤进行操作: 1. 首先,你需要安装ONNXRuntime。可以通过pip命令来安装,例如在命令行中执行以下命令: ``` pip install onnxruntime ``` 2. 安装完成后,你可以导入ONNXRuntime库并加载你的ONNX模型。例如,在Python中执行以下代码: ```python import onnxruntime # 加载ONNX模型 model = onnxruntime.InferenceSession('your_model.onnx') ``` 3. 接下来,你可以准备输入数据并进行推理。例如,如果你的模型接受一个输入张量`input_data`,你可以执行以下代码进行推理: ```python import numpy as np # 准备输入数据 input_data = np.random.randn(1, 3, 224, 224).astype(np.float32) # 进行推理 output = model.run(None, {'input': input_data}) ``` 这里的`'input'`是你模型的输入名称,你需要根据你的模型进行相应的修改。 4. 最后,你可以获取推理结果并进行后续处理。例如,如果你的模型输出一个张量`output`,你可以执行以下代码获取结果: ```python # 获取推理结果 result = output[0] # 进行后续处理 # ... ``` 这里的`output[0]`表示获取第一个输出张量,你可以根据你的模型进行相应的修改。 通过以上步骤,你可以使用ONNXRuntime进行ONNX模型推理。希望对你有帮助![1][2][3]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liguiyuan112

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值