onnx_runtime 推理

onnx_runtime 推理

import numpy as np
import onnx
import onnxruntime as rt
 
#create input data
input_data = np.ones((1, 3, 299, 299), dtype=np.float32)
#create runtime session
sess = rt.InferenceSession("inception_v3.onnx")
# get output name
input_name = sess.get_inputs()[0].name
print("input name", input_name)
output_name= sess.get_outputs()[0].name
print("output name", output_name)
output_shape = sess.get_outputs()[0].shape
print("output shape", output_shape)
#forward model
res = sess.run([output_name], {input_name: input_data})
out = np.array(res)

posted @ 2023-08-11 18:10  michaelchengjl  阅读(66)  评论(0编辑  收藏  举报