+
    œ°³j™(  ã                   ó  € ^ RI HtHtHt ^RIHtHtHtHtH	t	 ^RI
HtHt ]! 4       '       d   ^ RIHt ^RIHtHt ]! 4       '       d   ^ RIt^ RIHt ^RIHt ]P.                  ! ]4      t]! ]! R	R
7      4       ! R R]4      4       tR# )é    )ÚAnyÚUnionÚoverload)Úadd_end_docstringsÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backends)ÚChunkPipelineÚbuild_pipeline_init_args)ÚImage)Ú
load_imageÚvalid_imagesN)ÚBaseModelOutput)Ú2MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMEST)Úhas_image_processorc                   óÌ   a a€ ] tR t^t oRtRtRtRtRtV 3R lt	]
V3R lR l4       t]
V3R lR l4       tRV3R	 lV 3R
 llltR tRR ltR tRR ltV3R lR ltRtVtV ;t# )ÚZeroShotObjectDetectionPipelineaN  
Zero shot object detection pipeline using `OwlViTForObjectDetection`. This pipeline predicts bounding boxes of
objects when you provide an image and a set of `candidate_labels`.

Example:

```python
>>> from transformers import pipeline

>>> detector = pipeline(model="google/owlvit-base-patch32", task="zero-shot-object-detection")
>>> detector(
...     "http://images.cocodataset.org/val2017/000000039769.jpg",
...     candidate_labels=["cat", "couch"],
... )
[{'score': 0.287, 'label': 'cat', 'box': {'xmin': 324, 'ymin': 20, 'xmax': 640, 'ymax': 373}}, {'score': 0.254, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}}, {'score': 0.121, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}}]

>>> detector(
...     "https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png",
...     candidate_labels=["head", "bird"],
... )
[{'score': 0.119, 'label': 'bird', 'box': {'xmin': 71, 'ymin': 170, 'xmax': 410, 'ymax': 508}}]
```

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

This object detection pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"zero-shot-object-detection"`.

See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=zero-shot-object-detection).
FTc                ój   <€ \         SV `  ! R/ VB  \        V R 4       V P                  \        4       R# )ÚvisionN© )ÚsuperÚ__init__r
   Úcheck_model_typer   )ÚselfÚkwargsÚ	__class__s   &,€Úr/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/pipelines/zero_shot_object_detection.pyr   Ú(ZeroShotObjectDetectionPipeline.__init__=   s,   ø€ Ü‰ÒÑ"˜6Ò"ä˜$ Ô)Ø×ÑÔPÖQó    c                óŒ   <€ V ^8„  d   QhRS[ S[R3,          RS[S[S[,          ,          RS[RS[S[S[S[3,          ,          /# )é   ÚimageúImage.ImageÚcandidate_labelsr   Úreturn)r   ÚstrÚlistr   Údict)ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú,ZeroShotObjectDetectionPipeline.__annotate__D   sL   ø€ ÷ #ñ #Ù™3 Ð-Õ.ð#ÙBEÉÉSÍ	Å/ð#Ù]`ð#á	‰d‘3™�8�nÕ	ñ#r    c                ó   € R # ©Nr   )r   r#   r%   r   s   &&&,r   Ú__call__Ú(ZeroShotObjectDetectionPipeline.__call__C   s   € ñ  #r    c          
      óˆ   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          RS[RS[ S[ S[S[S[3,          ,          ,          /# )r"   r#   r   r&   )r(   r)   r'   r   )r*   r+   s   "€r   r,   r-   I   s<   ø€ ×eÑe™d¡4©©S¨¥>Õ2Ðe¹cÐeÁdÉ4ÑPTÑUXÑZ]ÐU]ÕP^ÕK_ÕF`Ñer    c                ó   € R # r/   r   )r   r#   r   s   &&,r   r0   r1   H   s   € Ùber    c                ó
  <€ V ^8„  d   QhRS[ S[RS[S[S[S[3,          ,          3,          RS[S[S[,          ,          R,          RS[RS[S[S[S[3,          ,          S[S[S[S[S[3,          ,          ,          ,          /# )r"   r#   r$   r%   Nr   r&   )r   r'   r(   r)   r   )r*   r+   s   "€r   r,   r-   K   sƒ   ø€ ÷ Vñ Vá‘S˜-©©d±3¹°8­nÕ)=Ð=Õ>ðVñ ¡¡S¥	�/¨DÕ0ðVñ ð	Vñ
 
‰d‘3™�8�nÕ	¡¡T©$©s±C¨x­.Õ%9Õ :Õ	:ñVr    c           	     óh  <€ RV9   d   VP                  R4      p\        V\        \        P                  34      '       d   RVRV/pMZ\        V\        \
        34      '       d<   \        V4      '       d+   \	        \        SV `   ! R \        W4       4       3/ VB 4      #  Tp\        SV `   ! V3/ VB pV# )a$  
Detect objects (bounding boxes & classes) in the image(s) passed as inputs.

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

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

        You can use this parameter to send directly a list of images, or a dataset or a generator like so:

        ```python
        >>> from transformers import pipeline

        >>> detector = pipeline(model="google/owlvit-base-patch32", task="zero-shot-object-detection")
        >>> detector(
        ...     [
        ...         {
        ...             "image": "http://images.cocodataset.org/val2017/000000039769.jpg",
        ...             "candidate_labels": ["cat", "couch"],
        ...         },
        ...         {
        ...             "image": "http://images.cocodataset.org/val2017/000000039769.jpg",
        ...             "candidate_labels": ["cat", "couch"],
        ...         },
        ...     ]
        ... )
        [[{'score': 0.287, 'label': 'cat', 'box': {'xmin': 324, 'ymin': 20, 'xmax': 640, 'ymax': 373}}, {'score': 0.25, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}}, {'score': 0.121, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}}], [{'score': 0.287, 'label': 'cat', 'box': {'xmin': 324, 'ymin': 20, 'xmax': 640, 'ymax': 373}}, {'score': 0.254, 'label': 'cat', 'box': {'xmin': 1, 'ymin': 55, 'xmax': 315, 'ymax': 472}}, {'score': 0.121, 'label': 'couch', 'box': {'xmin': 4, 'ymin': 0, 'xmax': 642, 'ymax': 476}}]]
        ```


    candidate_labels (`str` or `list[str]` or `list[list[str]]`):
        What the model should recognize in the image.

    threshold (`float`, *optional*, defaults to 0.1):
        The probability necessary to make a prediction.

    top_k (`int`, *optional*, defaults to None):
        The number of top predictions that will be returned by the pipeline. If the provided number is `None`
        or higher than the number of predictions available, it will default to the number of predictions.

    timeout (`float`, *optional*, defaults to None):
        The maximum time in seconds to wait for fetching images from the web. If None, no timeout is set and
        the call may block forever.


Return:
    A list of lists containing prediction results, one list per input image. Each list contains dictionaries
    with the following keys:

    - **label** (`str`) -- Text query corresponding to the found object.
    - **score** (`float`) -- Score corresponding to the object (between 0 and 1).
    - **box** (`dict[str,int]`) -- Bounding box of the detected object in image's original size. It is a
      dictionary with `x_min`, `x_max`, `y_min`, `y_max` keys.
Útext_queriesr#   r%   c              3   ó2   "  € T F  w  rR VRV/x € K  	  R# 5i)r#   r%   Nr   )Ú.0ÚimgÚlabelss   &  r   Ú	<genexpr>Ú;ZeroShotObjectDetectionPipeline.__call__.<locals>.<genexpr>’   s   é € ÐpÑSoÁKÀC�g˜sÐ$6¸Õ?ÓSoùs   ‚)
ÚpopÚ
isinstancer'   r   r(   Útupler   r   r0   Úzip)r   r#   r%   r   ÚinputsÚresultsr   s   &&&,  €r   r0   r1   K   s´   ø€ ð~ ˜VÔ#Ø%Ÿz™z¨.Ó9Ðä�eœc¤5§;¡;Ð/×0Ò0Ø˜uÐ&8Ð:JÐK‰FÜ˜¤¤e˜}×-Ò-´,¸u×2EÒ2EÜÜ‘Ò ÙpÔSVÐW\ÔSoÓpñàñóð ðð ˆFä‘'Ò" 6Ñ4¨VÑ4ˆØˆr    c                ó†   € / pR V9   d   VR ,          VR &   / pRV9   d   VR,          VR&   RV9   d   VR,          VR&   V/ V3# )ÚtimeoutÚ	thresholdÚtop_kr   )r   r   Úpreprocess_paramsÚpostprocess_paramss   &,  r   Ú_sanitize_parametersÚ4ZeroShotObjectDetectionPipeline._sanitize_parameters£   sc   € ØÐØ˜ÔØ+1°)Õ+<Ð˜iÑ(ØÐØ˜&Ô Ø.4°[Õ.AÐ˜{Ñ+Ø�fÔØ*0°­/Ð˜wÑ'Ø  "Ð&8Ð8Ð8r    c              #  óü  "  € \        VR ,          VR7      pVR,          p\        V\        4      '       d   VP                  R4      p\        P
                  ! VP                  VP                  ..\        P                  R7      p\        V4       Fg  w  rgV P                  VRR7      pV P                  VRR7      p	V	P                  V P                  4      p	RV\        V4      ^,
          8H  RVR	V/VCV	Cx € Ki  	  R
# 5i)r#   )rD   r%   Ú,)ÚdtypeÚpt)Úreturn_tensorsÚis_lastÚtarget_sizeÚcandidate_labelN)r   r>   r'   ÚsplitÚtorchÚtensorÚheightÚwidthÚint32Ú	enumerateÚ	tokenizerÚimage_processorÚtorM   Úlen)
r   rA   rD   r#   r%   rQ   ÚirR   Útext_inputsÚimage_featuress
   &&&       r   Ú
preprocessÚ*ZeroShotObjectDetectionPipeline.preprocess®   sï   é € Ü˜6 '�?°GÔ<ˆØ!Ð"4Õ5ÐÜÐ&¬×,Ò,Ø/×5Ñ5°cÓ:Ðä—l’l U§\¡\°5·;±;Ð$?Ð#@ÌÏÉÔTˆÜ"+Ð,<Ö"=ÑˆAØŸ.™.¨È˜.ÓNˆKØ!×1Ñ1°%ÈÐ1ÓMˆNØ+×.Ñ.¨t¯z©zÓ:ˆNà˜1¤Ð$4Ó 5¸Õ 9Ñ9Ø˜{Ø! ?ðð ð	ð
 !ðô ó	 #>ùs   ‚C:C<c                ó¤   € VP                  R 4      pVP                  R4      pVP                  R4      pV P                  ! R/ VB pR VRVRV/VCpV# )rQ   rR   rP   r   )r=   Úmodel)r   Úmodel_inputsrQ   rR   rP   ÚoutputsÚmodel_outputss   &&     r   Ú_forwardÚ(ZeroShotObjectDetectionPipeline._forwardÁ   se   € Ø"×&Ñ& }Ó5ˆØ&×*Ñ*Ð+<Ó=ˆØ×"Ñ" 9Ó-ˆà—*’*Ñ,˜|Ñ,ˆà&¨Ð5FÈÐYbÐdkÐwÐovÐwˆØÐr    c                óÈ  € . pV F½  pVR ,          p\        V4      pV P                  P                  WRVR,          R7      ^ ,          pVR,          P                  4        F`  pVR,          V,          P	                  4       p	V P                  VR,          V,          ^ ,          4      p
RV	RVRV
/pVP                  V4       Kb  	  K¿  	  \        VR R	R
7      pV'       d   VRV pV# )rR   rQ   )rf   rE   Útarget_sizesÚscoresÚboxesÚscoreÚlabelÚboxc                 ó   € V R ,          # )rn   r   )Úxs   &r   Ú<lambda>Ú=ZeroShotObjectDetectionPipeline.postprocess.<locals>.<lambda>Û   s   € °°'¶
r    T)ÚkeyÚreverseN)r   r[   Úpost_process_object_detectionÚnonzeroÚitemÚ_get_bounding_boxÚappendÚsorted)r   rg   rE   rF   rB   Úmodel_outputro   rf   Úindexrn   rp   Úresults   &&&&        r   ÚpostprocessÚ+ZeroShotObjectDetectionPipeline.postprocessË   sè   € ØˆÛ)ˆLØ Ð!2Õ3ˆEÜ*¨<Ó8ˆLØ×*Ñ*×HÑHØ$ÈÐUbÕHcð Ió àõˆGð ! Õ*×2Ñ2Ö4�Ø Õ)¨%Õ0×5Ñ5Ó7�Ø×,Ñ,¨W°WÕ-=¸eÕ-DÀQÕ-GÓH�à! 5¨'°5¸%ÀÐE�Ø—‘˜vÖ&ó 5ñ *ô ˜Ñ&:ÀDÔIˆßØ˜f˜u�oˆGàˆr    c                ó:   <€ V ^8„  d   QhRRRS[ S[S[3,          /# )r"   rp   ztorch.Tensorr&   )r)   r'   Úint)r*   r+   s   "€r   r,   r-   á   s#   ø€ ÷ ñ  ^ð ¹¹SÁ#¸X½ñ r    c                ó\   € VP                  4       P                  4       w  r#rERVRVRVRV/pV# )zõ
Turns list [xmin, xmax, ymin, ymax] into dict { "xmin": xmin, ... }

Args:
    box (`torch.Tensor`): Tensor containing the coordinates in corners format.

Returns:
    bbox (`dict[str, int]`): Dict containing the coordinates in corners format.
ÚxminÚyminÚxmaxÚymax)rƒ   Útolist)r   rp   r…   r†   r‡   rˆ   Úbboxs   &&     r   rz   Ú1ZeroShotObjectDetectionPipeline._get_bounding_boxá   s?   € ð "%§¡£×!1Ñ!1Ó!3Ñˆ�Dà�DØ�DØ�DØ�Dð	
ˆð ˆr    r   r/   )gš™™™™™¹?N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r   r0   rI   ra   rh   r€   rz   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r   r+   s   @@r   r   r      s}   ù‡ € ñð@ €OØ ÐØ#ÐØ€OõRð ÷#ó ð#ð ßeó Øe÷Võ Vòp	9ôò&ô÷,÷ ð r    r   )Útypingr   r   r   Úutilsr   r   r   r	   r
   Úbaser   r   ÚPILr   Úimage_utilsr   r   rT   Útransformers.modeling_outputsr   Úmodels.auto.modeling_autor   Ú
get_loggerrŒ   Úloggerr   r   r    r   Ú<module>r¡      sq   ðß 'Ñ 'ç kÕ kß 9ñ ×ÒÝç6á×ÒÛå=å^à	×	Ò	˜HÓ	%€ñ Ñ,ÀÔFÓGô[ mó [ó Hò[r    