onnx.utils

Extractor

class 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) – 是否推斷原始模型的形狀。