You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenVINO 2022.3.0 Output类缺失问题及IR模型中间输出获取方法咨询

OpenVINO获取IR模型中间输出的解决方案

关于openvino.runtime.Output缺失的说明

OpenVINO 2022.3.0并非存在bug,而是Python API做了结构调整,Output类不再通过openvino.runtime.Output直接访问,而是通过模型节点的属性获取相关输出对象。

获取中间输出的两种常用方法

方法1:通过Python API直接获取节点输出

加载IR模型后,遍历模型所有节点,定位到目标中间节点,再获取其输出张量。示例代码如下:

from openvino.runtime import Core

# 加载IR模型
core = Core()
model = core.read_model(model="your_model.xml", weights="your_model.bin")

# 替换为你需要的中间节点名称
target_node_name = "target_layer_name"
for node in model.get_ops():
    if node.get_friendly_name() == target_node_name:
        # 获取节点的第0个输出(多输出节点可调整索引)
        intermediate_output = node.output(0)
        print(f"中间输出形状: {intermediate_output.get_shape()}")
        break

方法2:修改IR模型,将中间层设为模型输出

有两种方式实现:

  • 转换IR时指定:用Model Optimizer转换模型为IR格式时,添加--output参数指定需要的中间层名称,多个层用逗号分隔。示例命令:
mo --input_model your_model.onnx --output target_layer_name1,target_layer_name2
  • 加载模型后修改:通过Python API加载模型后,手动将目标节点输出添加为模型输出,示例代码:
from openvino.runtime import Core

core = Core()
model = core.read_model(model="your_model.xml", weights="your_model.bin")

# 查找目标节点(这里通过索引示例,也可按名称查找)
target_node = model.get_ops()[your_target_index]
# 添加节点输出到模型输出列表
model.add_outputs([target_node.output(0)])

# 可选:保存修改后的模型
core.save_model(model, "modified_model.xml")

内容的提问来源于stack exchange,提问作者SantiaSantia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 17:00:11