o
    åe¤  ã                   @   sŒ   d Z ddlZddlm  mZ ddlmZ ddlmZ ddeee	f de
de
d	e
d
ef
dd„Zddedede
de
d	e
d
dfdd„ZejZdS )zIonnx shape inference. Shape inference is not guaranteed to be
complete.

é    N)Ú
ModelProto)ÚUnionFÚmodelÚ
check_typeÚstrict_modeÚ	data_propÚreturnc                 C   sb   t | ttfƒrt | tƒr| n|  ¡ }t ||||¡}t |¡S t | tƒr(t	dƒ‚t	d 
t| ƒ¡ƒ‚)a  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.

    Arguments:
        model (Union[ModelProto, bytes], bool, bool, bool) -> ModelProto
        check_type (bool): Checks the type-equality for input and output
        strict_mode (bool): Stricter shape inference, it will throw errors if any;
            Otherwise, simply stop if any error
        data_prop (bool): Enables data propagation for limited operators to perform shape computation

    Returns:
        (ModelProto) model with inferred shape information
    zhinfer_shapes only accepts ModelProto or bytes,you can use infer_shapes_path for the model path (String).zAinfer_shapes only accepts ModelProto or bytes, incorrect type: {})Ú
isinstancer   ÚbytesZSerializeToStringÚCÚinfer_shapesÚonnxZload_from_stringÚstrÚ	TypeErrorÚformatÚtype)r   r   r   r   Z	model_strZinferred_model_str© r   úDD:\Projects\ConvertPro\env\Lib\site-packages\onnx/shape_inference.pyr      s   


ÿr   Ú Ú
model_pathÚoutput_pathc                 C   sP   t | tƒr	tdƒ‚t | tƒr|dkr| }t | ||||¡ dS td t| ƒ¡ƒ‚)z·
    Take model path for shape_inference same as infer_shape; it support >2GB models
    Directly output the inferred model to the output_path; Default is the original model path
    z_infer_shapes_path only accepts model Path (String),you can use infer_shapes for the ModelProto.r   zFinfer_shapes_path only accepts model path (String), incorrect type: {}N)r	   r   r   r   r   Úinfer_shapes_pathr   r   )r   r   r   r   r   r   r   r   r   ,   s   


ÿr   )FFF)r   FFF)Ú__doc__r   Z'onnx.onnx_cpp2py_export.shape_inferenceZonnx_cpp2py_exportZshape_inferencer   r   Útypingr   r
   Úboolr   r   r   ZInferenceErrorr   r   r   r   Ú<module>   s   ($
