Ë
    T^(h|  ã                   óŠ   — d dl mZ ddlmZmZ ddlmZmZmZ  e«       rddl	m
Z
  e ed¬«      d	«       G d
„ de«      «       Zy)é    )ÚDicté   )Úadd_end_docstringsÚis_vision_availableé   )ÚGenericTensorÚPipelineÚbuild_pipeline_init_args)Ú
load_imageT)Úhas_image_processora  
        image_processor_kwargs (`dict`, *optional*):
                Additional dictionary of keyword arguments passed along to the image processor e.g.
                {"size": {"height": 100, "width": 100}}
        pool (`bool`, *optional*, defaults to `False`):
            Whether or not to return the pooled output. If `False`, the model will return the raw hidden states.
    c                   óP   ‡ — e Zd ZdZdd„Zd	deeef   fd„Zd„ Z	d
d„Z
ˆ fd„Zˆ xZS )ÚImageFeatureExtractionPipelinea+  
    Image feature extraction pipeline uses no model head. This pipeline extracts the hidden states from the base
    transformer, which can be used as features in downstream tasks.

    Example:

    ```python
    >>> from transformers import pipeline

    >>> extractor = pipeline(model="google/vit-base-patch16-224", task="image-feature-extraction")
    >>> result = extractor("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png", return_tensors=True)
    >>> result.shape  # This is a tensor of shape [1, sequence_lenth, hidden_dimension] representing the input image.
    torch.Size([1, 197, 768])
    ```

    Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)

    This image feature extraction pipeline can currently be loaded from [`pipeline`] using the task identifier:
    `"image-feature-extraction"`.

    All vision models may be used for this pipeline. See a list of all models, including community-contributed models on
    [huggingface.co/models](https://huggingface.co/models).
    c                 óP   — |€i n|}i }|�||d<   |�||d<   d|v r|d   |d<   |i |fS )NÚpoolÚreturn_tensorsÚtimeout© )ÚselfÚimage_processor_kwargsr   r   ÚkwargsÚpreprocess_paramsÚpostprocess_paramss          úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/pipelines/image_feature_extraction.pyÚ_sanitize_parametersz3ImageFeatureExtractionPipeline._sanitize_parameters.   s_   € Ø"8Ð"@™BÐF\ÐàÐØÐØ)-Ð˜vÑ&ØÐ%Ø3AÐÐ/Ñ0à˜ÑØ+1°)Ñ+<Ð˜iÑ(à  "Ð&8Ð8Ð8ó    Úreturnc                 ó²   — t        ||¬«      } | j                  |fd| j                  i|¤Ž}| j                  dk(  r|j                  | j                  «      }|S )N)r   r   Úpt)r   Úimage_processorÚ	frameworkÚtoÚtorch_dtype)r   Úimager   r   Úmodel_inputss        r   Ú
preprocessz)ImageFeatureExtractionPipeline.preprocess<   sU   € Ü˜5¨'Ô2ˆØ+�t×+Ñ+¨EÑkÀ$Ç.Á.ÐkÐTjÑkˆØ�>‰>˜TÒ!Ø'Ÿ?™?¨4×+;Ñ+;Ó<ˆLØÐr   c                 ó*   —  | j                   di |¤Ž}|S )Nr   )Úmodel)r   r$   Úmodel_outputss      r   Ú_forwardz'ImageFeatureExtractionPipeline._forwardC   s   € Ø"˜Ÿ
™
Ñ2 \Ñ2ˆØÐr   c                 óè   — |�|nd}|rd|vrt        d«      ‚|d   }n|d   }|r|S | j                  dk(  r|j                  «       S | j                  dk(  r|j                  «       j                  «       S y )NFÚpooler_outputzeNo pooled output was returned. Make sure the model has a `pooler` layer when using the `pool` option.r   r   Útf)Ú
ValueErrorr    ÚtolistÚnumpy)r   r(   r   r   Úoutputss        r   Úpostprocessz*ImageFeatureExtractionPipeline.postprocessG   sˆ   € ØÐ'‰t¨UˆáØ mÑ3Ü Ø{óð ð $ OÑ4‰Gð $ AÑ&ˆGáØˆNØ�>‰>˜TÒ!Ø—>‘>Ó#Ð#Ø�^‰^˜tÒ#Ø—=‘=“?×)Ñ)Ó+Ð+ð $r   c                 ó"   •— t        ‰| �  |i |¤ŽS )aÇ  
        Extract the features of the input(s).

        Args:
            images (`str`, `List[str]`, `PIL.Image` or `List[PIL.Image]`):
                The pipeline handles three types of images:

                - A string containing a http link pointing to an image
                - A string containing a local path to an image
                - An image loaded in PIL directly

                The pipeline accepts either a single image or a batch of images, which must then be passed as a string.
                Images in a batch must all be in the same format: all as http links, all as local paths, or all as PIL
                images.
            timeout (`float`, *optional*, defaults to None):
                The maximum time in seconds to wait for fetching images from the web. If None, no timeout is used and
                the call may block forever.
        Return:
            A nested list of `float`: The features computed by the model.
        )ÚsuperÚ__call__)r   Úargsr   Ú	__class__s      €r   r4   z'ImageFeatureExtractionPipeline.__call__[   s   ø€ ô* ‰wÑ Ð0¨Ñ0Ð0r   )NNN)N)NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústrr   r%   r)   r1   r4   Ú__classcell__)r6   s   @r   r   r      s9   ø„ ñó09ñÈ4ÐPSÐUbÐPbÑKcó òó,÷(1ð 1r   r   N)Útypingr   Úutilsr   r   Úbaser   r	   r
   Úimage_utilsr   r   r   r   r   ú<module>rA      sL   ðÝ ç ;ß CÑ Cñ ÔÝ(ñ Ù°Ô6ðó	ô[1 Xó [1ó	ñ[1r   