onnx.utils¶
Extractor¶
- 类 onnx.utils.Extractor(model: ModelProto)[源代码]¶
extract_model¶
- onnx.utils.extract_model(input_path: str | PathLike, output_path: str | PathLike, input_names: list[str], output_names: list[str], check_model: bool = True, infer_shapes: bool = True) None [源代码]¶
从 ONNX 模型中提取子模型。
子模型*精确地*由输入和输出张量的名称定义。
注意:对于控制流运算符(例如 If 和 Loop),由输入和输出张量定义的子模型边界不应穿过作为这些运算符属性连接到主图的子图。
注意:当提取的模型大小大于 2GB 时,额外数据将保存在“output_path.data”中。
- 参数:
input_path (str | os.PathLike) – 原始 ONNX 模型的路径。
output_path (str | os.PathLike) – 保存提取的 ONNX 模型的路径。
input_names (list of string) – 要提取的输入张量的名称。
output_names (list of string) – 要提取的输出张量的名称。
check_model (bool) – 是否在原始模型和提取的模型上运行模型检查器。
infer_shapes (bool) – 是否推断原始模型的形状。