有什么方法可以获取onnx模型的每层推理时间吗?

问题描述 投票:0回答:1

代码就像

import onnxruntime

onnx_input= np.random.normal(size=[1, 3, 224, 224]).astype(np.float32)
ort_sess = onnxruntime.InferenceSession('model.onnx')
ort_inputs = {ort_sess.get_inputs()[0].name: onnx_input}
ort_outs = ort_sess.run(None, ort_inputs)

我可以从ort_outs获取网络输出,但是如何获取模型每一层的推理时间?

我可以通过

获取模型图信息
import onnx
model = onnx.load("model.onnx")
print(onnx.helper.printable_graph(model.graph))

或通过

获取总推理时间
import time

start = time.time()
ort_outs = ort_sess.run(None, ort_inputs)
end = time.time()
print(end - start)

但我不知道如何获得神经网络每层的推理时间。谢谢!

python neural-network onnx onnxruntime
1个回答
0
投票

请参阅 https://onnxruntime.ai/docs/performance/tune-performance/profiling-tools.html 了解有关启用单个节点分析的详细信息。

请注意,由于输出分析数据的开销,在测量每个节点的性能时,整体推理时间将毫无意义。

© www.soinside.com 2019 - 2024. All rights reserved.