o
    0j                     @  s   d dl mZ d dlmZmZ d dlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZ dd	lmZ G d
d deedZdS )    )annotations)ABCabstractmethod)AnyDictOptionalUnion   )logging)AutoRegisterABCMetaClass   )BasePredictor	HPIConfigPaddlePredictorOption)uses_server_backendc                      st   e Zd ZdZdZdddddddd) fddZedd Zed*ddZ	d+d d!Z
d,d#d$Zd%d& Zd'd( Z  ZS )-BasePipelinezBase class for all pipelines.

    This class serves as a foundation for creating various pipelines.
    It includes common attributes and methods that are shared among all
    pipeline implementations.
    TNF)deviceengineengine_config	pp_optionuse_hpip
hpi_configr   Optional[str]r   r   Optional[Dict[str, Any]]r   Optional[PaddlePredictorOption]r   boolr   *Optional[Union[Dict[str, Any], HPIConfig]]returnNonec                  s2   t    || _|| _|| _|| _|| _|| _dS )a  
        Initializes the class with specified parameters.

        Args:
            device (Optional[str], optional): The device to use for prediction. Defaults to `None`.
            engine (Optional[str], optional): Inference engine. Defaults to `None`.
            engine_config (Optional[Dict[str, Any]], optional): Engine-specific config. Defaults to `None`.
            pp_option (Optional[PaddlePredictorOption], optional): Paddle predictor options.
                Defaults to `None`.
            use_hpip (bool, optional): Whether to use HPIP. Defaults to `False`.
            hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional): HPIP configuration.
                Defaults to `None`.
        N)super__init__r   r   r   r   r   r   )selfr   r   r   r   r   r   kwargs	__class__ a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/pipelines/base.pyr    $   s   

zBasePipeline.__init__c                 K  s   t d)z
        Declaration of an abstract method. Subclasses are expected to
        provide a concrete implementation of `predict`.
        Args:
            input: The input data to predict.
            **kwargs: Additional keyword arguments.
        z2The method `predict` has not been implemented yet.)NotImplementedErrorr!   inputr"   r%   r%   r&   predictD   s   	zBasePipeline.predictconfigDict[str, Any]inherited_engineallow_genaituple[Optional[str], bool]c                C  sP   d| v r|  dd}||du fS d| v }|r t|  ddr d}|r$dS |dfS )a  Resolve the effective child engine.

        Returns a tuple of `(engine, suppress_inherited_engine_defaults)`.

        Same-level `engine` has the highest priority. If a child omits `engine`
        but specifies another engine selector such as `use_hpip`, or a
        `genai_config` that targets a remote server backend, that selector
        should beat the inherited parent `engine` and fall back to local
        auto-resolution instead of reusing the parent engine defaults.
        r   Nr   genai_configT)NTF)getr   )r+   r-   r.   Zchild_engineZhas_local_engine_selectorr%   r%   r&   _resolve_child_engineO   s   z"BasePipeline._resolve_child_enginer   r   c                 K  sH  d|v r
t |d |dd}| j|| jdd\}}|dd}| jdur6|s6t| j}|r4|| |}|d| j}|dd}	| jdurj|	pKi }	t	| jd	rY| jj
dd
n
t| jtrb| jni }
i |
|	}	ddlm} td|d ||f | jdur| j nd}|d|d || j|||dd|||	|ddd
|S )zK
        Create a model instance based on the given configuration.
        Zmodel_config_error	model_dirNTr.   r   r   r   
model_dumpZexclude_noner   )create_predictorzCreating model: %s
model_name
batch_size   r0   )
r8   r3   r   r   r   r9   r   r   r   r0   r%   )
ValueErrorr1   r2   r   r   dictupdater   r   hasattrr5   
isinstancemodelsr7   r
   infor   copyr   )r!   r+   r"   r3   Zmodel_engine"suppress_inherited_engine_defaultsZmodel_engine_configZmergedr   r   baser7   r   r%   r%   r&   create_modelj   sP   






zBasePipeline.create_model'BasePipeline'c           	   
   K  s   d|v r
t |d ddlm} | j|| jdd\}}|d| j}|dd}| jdurO|p0i }t| jd	r>| jj	d
dn
t
| jtrG| jni }i ||}|d|| j||rYdn| j| jdure| j nd||d|S )zI
        Creates a pipeline based on the provided configuration.
        Zpipeline_config_errorr:   )create_pipelineFr4   r   r   Nr5   Tr6   )r+   r   r   r   r   r   r   r%   )r;    rG   r2   r   r1   r   r   r>   r5   r?   r<   r   r   r   rB   )	r!   r+   r"   rG   Zpipeline_enginerC   r   r   rD   r%   r%   r&   rG      s2   


zBasePipeline.create_pipelinec                 C  s   d S )Nr%   )r!   r%   r%   r&   close   s   zBasePipeline.closec                 K  s   | j |fi |S )aB  
        Calls the `predict` method with the given input and keyword arguments.

        Args:
            input: The input data to be predicted.
            **kwargs: Additional keyword arguments to be passed to the `predict` method.

        Returns:
            The prediction result from the `predict` method.
        )r*   r(   r%   r%   r&   __call__   s   zBasePipeline.__call__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r+   r,   r-   r   r.   r   r   r/   )r+   r   r   r   )r+   r   r   rF   )__name__
__module____qualname____doc__Z_BasePipeline__is_baser    r   r*   staticmethodr2   rE   rG   rI   rJ   __classcell__r%   r%   r#   r&   r      s$     



3%r   )	metaclassN)
__future__r   abcr   r   typingr   r   r   r   utilsr
   Zutils.subclass_registerr   r@   r   r   r   Zmodels.common.genair   r   r%   r%   r%   r&   <module>   s   