onnx.shape_inference

infer_shapes

onnx.shape_inference.infer_shapes(model: ModelProto | bytes, check_type: bool = False, strict_mode: bool = False, data_prop: bool = False) ModelProto[源代码]

将形状推断应用于提供的 ModelProto。

推断出的形状会添加到图的 value_info 字段中。

如果推断出的值与图中已提供的值冲突,则表示提供的值无效(或形状推断存在错误),结果是未指定的。

参数:
  • model – ModelProto。

  • check_type – 检查输入和输出的类型是否相等。

  • strict_mode – 更严格的形状推断,如果遇到任何错误,将抛出异常;否则,遇到任何错误时仅停止。

  • data_prop – 为有限的算子启用数据传播以执行形状计算。

返回:

(ModelProto) 包含推断形状信息的模型

infer_shapes_path

onnx.shape_inference.infer_shapes_path(model_path: str | PathLike, output_path: str | PathLike = '', check_type: bool = False, strict_mode: bool = False, data_prop: bool = False) None[源代码]

使用模型路径进行形状推断。

此函数与 infer_shape() 相同,但支持大于 2GB 的模型。该函数将推断出的模型输出到 output_path。如果未指定,则使用原始模型路径。

infer_node_outputs

onnx.shape_inference.infer_node_outputs(schema: OpSchema, node: NodeProto, input_types: dict[str, TypeProto], input_data: dict[str, TensorProto] | None = None, input_sparse_data: dict[str, SparseTensorProto] | None = None, opset_imports: list[OperatorSetIdProto] | None = None, ir_version: int = 11) dict[str, TypeProto][源代码]

infer_function_output_types

onnx.shape_inference.infer_function_output_types(function: FunctionProto, input_types: Sequence[TypeProto], attributes: Sequence[AttributeProto]) list[TypeProto][源代码]

将类型和形状推断应用于给定的函数体,使用给定的输入类型和给定的输入属性值。