onnx 获取每个层的输出

def get_out(input):
    # 加载模型

    model = onnx.load('weights/truck-cls.onnx')

    # 模型推理
    ori_output = copy.deepcopy(model .graph.output)
    # 输出模型每层的输出
    for node in model.graph.node:
        for output in node.output:
            model.graph.output.extend([onnx.ValueInfoProto(name=output)])
    ort_session = onnxruntime.InferenceSession(model.SerializeToString())
    ort_inputs = {ort_session.get_inputs()[0].name: input}
    ort_outs = ort_session.run(None, ort_inputs)
    #获取所有节点输出
    outputs = [x.name for x in ort_session.get_outputs()]
    # 生成字典,便于查找层对应输出
    ort_outs = OrderedDict(zip(outputs, ort_outs))
    print("Mul_106")
    print(ort_outs["173"])

input 为输出图片