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) None[source]

Extracts sub-model from an ONNX model.

The sub-model is defined by the names of the input and output tensors exactly.

Note: For control-flow operators, e.g. If and Loop, the _boundary of sub-model_, which is defined by the input and output tensors, should not _cut through_ the subgraph that is connected to the _main graph_ as attributes of these operators.

  • input_path (str | os.PathLike) – The path to original ONNX model.

  • output_path (str | os.PathLike) – The path to save the extracted ONNX model.

  • input_names (list of string) – The names of the input tensors that to be extracted.

  • output_names (list of string) – The names of the output tensors that to be extracted.

  • check_model (bool) – Whether to run model checker on the extracted model.