onnx.utils

提取器

class onnx.utils.Extractor(model: ModelProto)[source]

提取模型

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”中。

Parameters:
  • 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) – 是否推断原始模型的形状。