Ë
    ÜÓ^jº  ã                   óš   — d dl mZ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 ddlmZ  e e	d¬	«      d
«       G d„ de«      «       Zy)é    )ÚAnyÚUnioné   )Úadd_end_docstringsÚis_vision_availableé   )ÚGenericTensorÚPipelineÚbuild_pipeline_init_args)ÚImage)Ú
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                   óŽ   ‡ — e Zd ZdZdZdZdZdZdd„Zdde	e
ef   fd„Zd„ Zdd„Zd	ee
d
ed
   ee
   f   dedee   fˆ 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_length, 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).
    FTc                 ó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          úz/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/pipelines/image_feature_extraction.pyÚ_sanitize_parametersz3ImageFeatureExtractionPipeline._sanitize_parameters5   s_   € Ø"8Ð"@™BÐF\ÐàÐØÐØ)-Ð˜vÑ&ØÐ%Ø3AÐÐ/Ñ0à˜ÑØ+1°)Ñ+<Ð˜iÑ(à  "Ð&8Ð8Ð8ó    Úreturnc                 ó€   — t        ||¬«      } | j                  |fddi|¤Ž}|j                  | j                  «      }|S )N)r   r   Úpt)r   Úimage_processorÚtoÚdtype)r   Úimager   r   Úmodel_inputss        r   Ú
preprocessz)ImageFeatureExtractionPipeline.preprocessC   sC   € Ü˜5¨'Ô2ˆØ+�t×+Ñ+¨EÑaÀ$ÐaÐJ`ÑaˆØ#—‘ t§z¡zÓ2ˆØÐr   c                 ó*   —  | j                   di |¤Ž}|S )Nr   )Úmodel)r   r%   Úmodel_outputss      r   Ú_forwardz'ImageFeatureExtractionPipeline._forwardI   s   € Ø"˜Ÿ
™
Ñ2 \Ñ2ˆØÐr   c                 ón   — |�|nd}|rd|vrt        d«      ‚|d   }n|d   }|r|S |j                  «       S )NFÚpooler_outputzeNo pooled output was returned. Make sure the model has a `pooler` layer when using the `pool` option.r   )Ú
ValueErrorÚtolist)r   r)   r   r   Úoutputss        r   Úpostprocessz*ImageFeatureExtractionPipeline.postprocessM   sV   € ØÐ'‰t¨UˆáØ mÑ3Ü Ø{óð ð $ OÑ4‰Gð $ AÑ&ˆGáØˆNØ�~‰~ÓÐr   ÚargszImage.Imager   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   r1   r   Ú	__class__s      €r   r4   z'ImageFeatureExtractionPipeline.__call__^   s   ø€ ô* ‰wÑ Ð0¨Ñ0Ð0r   )NNN)N)NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   ÚdictÚstrr	   r&   r*   r0   r   Úlistr   r4   Ú__classcell__)r5   s   @r   r   r      s†   ø„ ñð0 €OØ ÐØ#ÐØ€Oó9ñÈ4ÐPSÐUbÐPbÑKcó òó ð"1˜e C¨¸¸]Ñ8KÈTÐRUÉYÐ$VÑWð 1Ðcfð 1ÐkoÐpsÑkt÷ 1ñ 1r   r   N)Útypingr   r   Úutilsr   r   Úbaser	   r
   r   ÚPILr   Úimage_utilsr   r   r   r   r   ú<module>rG      sO   ðß ç ;ß CÑ Cñ ÔÝå(ñ Ù°Ô6ðó	ô\1 Xó \1ó	ñ\1r   