o
    0ju                     @   s   d dl mZmZmZmZmZ d dlZddlm	Z	 ddl
mZmZ ddlmZ ddlmZ d	d
lmZ eeef Zeje	dG dd deZdS )    )AnyDictListOptionalUnionN   )pipeline_requires_extra   )	HPIConfigPaddlePredictorOption)SAMSegResult)	benchmark   )BasePipelineZ
multimodalc                       s   e Zd ZdZdZddddddddedee dee d	eeeef  d
ee	 de
deeeeef ef  ddf fddZ	ddeeee ejeej f deeee  ejf dedefddZ  ZS )"OpenVocabularySegmentationPipelinez%Open Vocabulary Segmentation pipelineZopen_vocabulary_segmentationNFdeviceengineengine_config	pp_optionuse_hpip
hpi_configconfigr   r   r   r   r   r   returnc             	      sl   t  jd||||||d| |di dddi}	| |	| _|di dddi}
| |
| _dS )	a&  Initializes the open vocabulary segmentation pipeline.

        Args:
            config (Dict): Configuration dictionary containing model and other parameters.
            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`.
        r   Z
SubModulesZBoxPromptSegmentationZmodel_config_errorz(config error for doc_ori_classify_model!ZPointPromptSegmentationN )super__init__getZcreate_modelbox_prompted_modelpoint_prompted_model)selfr   r   r   r   r   r   r   kwargsZbox_prompted_model_cfgZpoint_prompted_model_cfg	__class__r   /var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/pipelines/open_vocabulary_segmentation/pipeline.pyr   #   s(   z+OpenVocabularySegmentationPipeline.__init__boxinputpromptprompt_typec                 k   sR    |dkr| j |d|idE dH  dS |dkr%| j|d|idE dH  dS td)a#  Predicts image segmentation results for the given input.

        Args:
            input (str | list[str] | np.ndarray | list[np.ndarray]): The input image(s) or path(s) to the images.
            prompt (list[list[float]] | np.ndarray): The prompt for the input image(s).
            prompt_type (str): The type of prompt, either 'box' or 'point'. Default is 'box'.
            **kwargs: Additional keyword arguments that can be passed to the function.

        Returns:
            SAMSegResult: The predicted SAM segmentation results.
        r%   Z
box_prompt)ZpromptsNpointZpoint_promptz9Invalid prompt type. Only 'box' and 'point' are supported)r   r   
ValueError)r    r&   r'   r(   r!   r   r   r$   predictT   s   z*OpenVocabularySegmentationPipeline.predict)r%   )__name__
__module____qualname____doc__entitiesr   r   strr   r   boolr   r
   r   r   npZndarrayfloatr   r+   __classcell__r   r   r"   r$   r      sH    	5r   )typingr   r   r   r   r   numpyr3   Z
utils.depsr   modelsr
   r   Z+models.open_vocabulary_segmentation.resultsr   Zutils.benchmarkr   baser   intr4   NumberZtime_methodsr   r   r   r   r$   <module>   s   