import onnx
import onnxruntime as rt
import os
import numpy as np
import argparse
class fix_dim_tools:
def __init__(self, model_path, inputs_shape, inputs_dtype):
assert os.path.exists(model_path), "{} not exists".format(model_path)
if inputs_dtype is None:
print('inputs_dtype is not define, use float for all inputs node')
inputs_dtype = ['float']*len(inputs_shape)
else:
assert len(inputs_shape)==len(inputs_dtype), "inputs shape list should have same length as inputs_dtype"
model = onnx.load(model_path)
self.model = model
self.model_path = model_path
self.inputs_shape = inputs_shape
self.inputs_dtype = inputs_dtype
self.inputs_shape_dict = {
}
self.inputs_type_dict = {
}
self.outputs_shape_dict = {
}
def check_dynamic_input(self):
# check dynamic input and get real input shape
inputs_number = len(self.model.graph.input)
assert inputs_number==len(self.inputs_shape),"model has {} inputs, but {} inputs_shape was given, not match".format(inputs_number,len(self.inputs_shape)
onnx动态模型转静态模型
最新推荐文章于 2025-07-08 17:56:11 发布
本文介绍如何将基于ONNX的动态深度学习模型转换为静态模型,以优化推理性能。通过Python接口,我们可以方便地进行模型转换,提升模型在实际应用中的效率。

最低0.47元/天 解锁文章
2096

被折叠的 条评论
为什么被折叠?



