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[source]#

Apply shape inference to the provided ModelProto.

Inferred shapes are added to the value_info field of the graph.

If the inferred values conflict with values already provided in the graph, that means that the provided values are invalid (or there is a bug in shape inference), and the result is unspecified.

Parameters:
  • model – ModelProto.

  • check_type – Checks the type-equality for input and output.

  • strict_mode – Stricter shape inference, it will throw errors if any; Otherwise, simply stop if any error.

  • data_prop – Enables data propagation for limited operators to perform shape computation.

Returns:

(ModelProto) model with inferred shape information

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[source]#

Take model path for shape_inference.

This function is the same as infer_shape() but supports >2GB models. The function outputs the inferred model to the output_path. The original model path is used if not specified.

infer_function_output_types#

onnx.shape_inference.infer_function_output_types(function: FunctionProto, input_types: Sequence[TypeProto], attributes: Sequence[AttributeProto]) list[TypeProto][source]#

Apply type-and-shape-inference to given function body, with given input types and given input attribute values.