code: def extract_model(
      input_path: str | os.PathLike,
      output_path: str | os.PathLike,
      input_names: list[str],
      output_names: list[str],
      check_model: bool = True,
  ) -> None:
      """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.
  
      Arguments:
          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.
      """
      if not os.path.exists(input_path):
          raise ValueError(f"Invalid input model path: {input_path}")
      if not output_path:
          raise ValueError("Output model path shall not be empty!")
      if not output_names:
          raise ValueError("Output tensor names shall not be empty!")
  
      onnx.checker.check_model(input_path)
      model = onnx.load(input_path)
  
      e = Extractor(model)
      extracted = e.extract_model(input_names, output_names)
  
      onnx.save(extracted, output_path)
      if check_model:
          onnx.checker.check_model(output_path)
  
file_path: onnx/onnx/utils.py
imports: from __future__ import annotations
  import os
  import onnx.checker
  import onnx.helper
  import onnx.shape_inference
  from onnx import FunctionProto, ModelProto, NodeProto, TensorProto, ValueInfoProto
label_desc: Use image node_id 1 for calling a global function with example usage: extract_model(input_path, output_path, input_names, output_names, check_model) without return types