+
    QV-jš   ã                   ó  € ^ RI Ht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 ]! 4       '       d   ^ RIt^RIHtHt ]'       d   ^ RIHt ]	P,                  ! ]4      t]! ]! RR	7      4       ! R
 R]4      4       tR# )é    )ÚTYPE_CHECKINGÚAnyÚUnionÚoverload)Úadd_end_docstringsÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backends)ÚPipelineÚbuild_pipeline_init_args)Ú
load_imageN)Ú(MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMESÚ,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES)ÚImageT)Ú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	R t
]V3R lR l4       t]V3R	 lR
 l4       tV3R lV 3R lltRR ltR tRR ltV3R lR ltRtVtV ;t# )ÚObjectDetectionPipelinea¶  
Object detection pipeline using any `AutoModelForObjectDetection`. This pipeline predicts bounding boxes of objects
and their classes.

Example:

```python
>>> from transformers import pipeline

>>> detector = pipeline(model="facebook/detr-resnet-50")
>>> detector("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")
[{'score': 0.997, 'label': 'bird', 'box': {'xmin': 69, 'ymin': 171, 'xmax': 396, 'ymax': 507}}, {'score': 0.999, 'label': 'bird', 'box': {'xmin': 398, 'ymin': 105, 'xmax': 767, 'ymax': 507}}]

>>> # x, y  are expressed relative to the top left hand corner.
```

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:
`"object-detection"`.

See the list of available models on [huggingface.co/models](https://huggingface.co/models?filter=object-detection).
FTNc                ó¶   <€ \         SV `  ! V/ VB  \        V R 4       \        P                  ! 4       pVP                  \        4       V P                  V4       R# )ÚvisionN)ÚsuperÚ__init__r   r   ÚcopyÚupdater   Úcheck_model_type)ÚselfÚargsÚkwargsÚmappingÚ	__class__s   &*, €Úx/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/pipelines/object_detection.pyr   Ú ObjectDetectionPipeline.__init__8   sH   ø€ Ü‰Ò˜$Ð) &Ò)ä˜$ Ô)Ü:×?Ò?ÓAˆØ�‰ÔCÔDØ×Ñ˜gÖ&ó    c                ó`   € / pR V9   d   VR ,          VR &   / pRV9   d   VR,          VR&   V/ V3# )ÚtimeoutÚ	threshold© )r   r   Úpreprocess_paramsÚpostprocess_kwargss   &,  r!   Ú_sanitize_parametersÚ,ObjectDetectionPipeline._sanitize_parameters@   sL   € ØÐØ˜ÔØ+1°)Õ+<Ð˜iÑ(ØÐØ˜&Ô Ø.4°[Õ.AÐ˜{Ñ+Ø  "Ð&8Ð8Ð8r#   c                ól   <€ V ^8„  d   QhRS[ S[R3,          RS[RS[RS[S[S[S[3,          ,          /# ©é   ÚimagezImage.Imager   r   Úreturn)r   Ústrr   ÚlistÚdict)ÚformatÚ__classdict__s   "€r!   Ú__annotate__Ú$ObjectDetectionPipeline.__annotate__J   s:   ø€ ×pÑp™e¡C¨Ð$6Õ7ÐpÁÐpÉsÐpÑW[Ñ\`ÑadÑfiÐaiÕ\jÕWkÑpr#   c                ó   € R # ©Nr'   ©r   r/   r   r   s   &&*,r!   Ú__call__Ú ObjectDetectionPipeline.__call__I   s   € Ùmpr#   c                ó–   <€ V ^8„  d   QhRS[ S[,          S[ R,          ,          RS[RS[RS[ S[ S[S[S[3,          ,          ,          /# r-   )r2   r1   r   r3   )r4   r5   s   "€r!   r6   r7   M   sM   ø€ ÷ )ñ )Ù™#•Y¡ mÕ!4Õ4ð)Ù=@ð)ÙLOð)á	‰d‘4™™S˜•>Õ"Õ	#ñ)r#   c                ó   € R # r9   r'   r:   s   &&*,r!   r;   r<   L   s   € ñ &)r#   c                óŒ   <€ V ^8„  d   QhRS[ S[S[S[3,          ,          S[ S[ S[S[S[3,          ,          ,          ,          /# )r.   r0   )r2   r3   r1   r   )r4   r5   s   "€r!   r6   r7   Q   s;   ø€ ÷ "1ñ "1©4±±S¹#°XµÕ+?Á$ÁtÉDÑQTÑVYÐQYÍNÕG[ÕB\Õ+\ñ "1r#   c                óh   <€ RV9   d   RV9  d   VP                  R4      VR&   \        SV `  ! V/ VB # )a±  
Detect objects (bounding boxes & classes) in the image(s) passed as inputs.

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

        - A string containing an HTTP(S) 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. Images in a batch must all be in the
        same format: all as HTTP(S) links, all as local paths, or all as PIL images.
    threshold (`float`, *optional*, defaults to 0.5):
        The probability necessary to make a prediction.
    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 dictionaries or a list of list of dictionaries containing the result. If the input is a single
    image, will return a list of dictionaries, if the input is a list of several images, will return a list of
    list of dictionaries corresponding to each image.

    The dictionaries contain the following keys:

    - **label** (`str`) -- The class label identified by the model.
    - **score** (`float`) -- The score attributed by the model for that label.
    - **box** (`list[dict[str, int]]`) -- The bounding box of detected object in image's original size.
ÚimagesÚinputs)Úpopr   r;   )r   r   r   r    s   &*,€r!   r;   r<   Q   s=   ø€ ð@ �vÔ (°&Ô"8Ø%Ÿz™z¨(Ó3ˆF�8ÑÜ‰wÒ Ð0¨Ñ0Ð0r#   c                ó>  € \        WR 7      p\        P                  ! VP                  VP                  ..4      pV P                  V.RR7      pVP                  V P                  4      pV P                  e#   V P                  VR,          VR,          RR7      pW4R&   V# ))r%   Úpt)rA   Úreturn_tensorsÚwordsÚboxes)ÚtextrH   rF   Útarget_size)	r   ÚtorchÚ	IntTensorÚheightÚwidthÚimage_processorÚtoÚdtypeÚ	tokenizer)r   r/   r%   rJ   rB   s   &&&  r!   Ú
preprocessÚ"ObjectDetectionPipeline.preprocessu   s‡   € Ü˜5Ô2ˆÜ—o’o¨¯©°e·k±kÐ'BÐ&CÓDˆØ×%Ñ%¨e¨WÀTÐ%ÓJˆØ—‘˜4Ÿ:™:Ó&ˆØ�>‰>Ò%Ø—^‘^¨°­ÀÀwÅÐ`d�^ÓeˆFØ +ˆ}ÑØˆr#   c                óª   € VP                  R 4      pV P                  ! R/ VB pVP                  R V/VC4      pV P                  e   VR,          VR&   V# )rJ   Úbboxr'   )rC   Úmodelr    rR   )r   Úmodel_inputsrJ   ÚoutputsÚmodel_outputss   &&   r!   Ú_forwardÚ ObjectDetectionPipeline._forward   s\   € Ø"×&Ñ& }Ó5ˆØ—*’*Ñ,˜|Ñ,ˆØ×)Ñ)¨=¸+Ð*QÈÐ*QÓRˆØ�>‰>Ò%Ø$0°Õ$8ˆM˜&Ñ!ØÐr#   c           	     ó¼  a aa€ VR ,          pS P                   Ee   V^ ,          P                  4       w  ooVV V3R lpVR,          P                  ^ 4      P                  RR7      P	                  RR7      w  rVVP                  4        Uu. uF*  pS P
                  P                  P                  V,          NK,  	  ppVR,          P                  ^ 4       U	u. uF
  q”! V	4      NK  	  p
p	. R	Op\        VP                  4       WŠ4       Uu. uF&  qÌ^ ,          V8”  g   K  \        \        W¼4      4      NK(  	  ppV# S P                  P                  WV4      pV^ ,          pVR,          pVR,          pVR,          p
VP                  4       VR&   V Uu. uF8  pS P
                  P                  P                  VP                  4       ,          NK:  	  upVR&   V
 Uu. uF  pS P                  V4      NK  	  upVR&   . R	Op\        VR,          VR,          VR,          4       Uu. uF  p\        \        W¼4      4      NK  	  ppV# u upi u up	i u upi u upi u upi u upi )
rJ   c           
      óþ   <€ SP                  \        P                  ! SV ^ ,          ,          R,          SV ^,          ,          R,          SV ^,          ,          R,          SV ^,          ,          R,          .4      4      # )r   iè  )Ú_get_bounding_boxrK   ÚTensor)rV   rM   r   rN   s   &€€€r!   ÚunnormalizeÚ8ObjectDetectionPipeline.postprocess.<locals>.unnormalizeŽ   si   ø€ Ø×-Ñ-Ü—L’Là" T¨!¥W�_¨tÕ3Ø# d¨1¥gÕ-°Õ4Ø" T¨!¥W�_¨tÕ3Ø# d¨1¥gÕ-°Õ4ð	óó	ð 	r#   Úlogits)ÚdimrV   ÚscoresÚlabelsrH   éÿÿÿÿ)ÚscoreÚlabelÚbox)rR   ÚtolistÚsqueezeÚsoftmaxÚmaxrW   ÚconfigÚid2labelÚzipr3   rO   Úpost_process_object_detectionÚitemr_   )r   rZ   r&   rJ   ra   re   ÚclassesÚ
predictionrf   rV   rH   ÚkeysÚvalsÚ
annotationÚraw_annotationsÚraw_annotationri   rj   rM   rN   s   f&&               @@r!   ÚpostprocessÚ#ObjectDetectionPipeline.postprocess‡   s4  ú€ Ø# MÕ2ˆØ�>‰>Ó%ð (¨�N×1Ñ1Ó3‰MˆF�E÷
ð ,¨HÕ5×=Ñ=¸aÓ@×HÑHÈRÐHÓP×TÑTÐY[ÐTÓ\‰OˆFØOVÏ~É~ÔO_Ó`ÑO_À�d—j‘j×'Ñ'×0Ñ0°×<Ð<ÑO_ˆFÐ`Ø3@ÀÕ3H×3PÑ3PÐQRÔ3SÓTÑ3S¨4�[ Ö&Ñ3SˆEÐTÚ,ˆDÜ<?ÀÇÁÃÐQWÔ<_ÓwÑ<_°DÐhiÕcjÐmvÑcvÔ/œ$œs 4›Ö/Ñ<_ˆJÐwð( Ðð# #×2Ñ2×PÑPÐQ^ÐkvÓwˆOØ,¨QÕ/ˆNØ# HÕ-ˆFØ# HÕ-ˆFØ" 7Õ+ˆEà'-§}¡}£ˆN˜8Ñ$Ù^dÓ'eÑ^dÐUZ¨¯
©
×(9Ñ(9×(BÑ(BÀ5Ç:Á:Ã<×(PÐ(PÑ^dÑ'eˆN˜8Ñ$ÙNSÓ&TÉeÀs t×'=Ñ'=¸cÖ'BÉeÑ&TˆN˜7Ñ#ò -ˆDô   ¨xÕ 8¸.ÈÕ:RÐTbÐcjÕTkÔlóál�Dô ”S˜“_Ö%Ùlð ð ð
 Ðùò/ aùÚTùâwùò (fùÚ&Tùòs*   Â
0I ÃIÄI
ÄI
Æ>IÇIÈIc                ó:   <€ V ^8„  d   QhRRRS[ S[S[3,          /# )r.   rj   ztorch.Tensorr0   )r3   r1   Úint)r4   r5   s   "€r!   r6   r7   ´   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~   rk   )r   rj   r€   r�   r‚   rƒ   rV   s   &&     r!   r_   Ú)ObjectDetectionPipeline._get_bounding_box´   s?   € ð "%§¡£×!1Ñ!1Ó!3Ñˆ�Dà�DØ�DØ�DØ�Dð	
ˆð ˆr#   r'   r9   )g      à?)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r*   r   r;   rS   r[   r{   r_   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r    r5   s   @@r!   r   r      sx   ù‡ € ñð0 €OØ ÐØ#ÐØ€Oõ'ò9ð ßpó Øpà÷)ó ð)÷"1ó "1ôHòô+÷Z÷ ð r#   r   )Útypingr   r   r   r   Úutilsr   r   r	   r
   r   Úbaser   r   Úimage_utilsr   rK   Úmodels.auto.modeling_autor   r   ÚPILr   Ú
get_loggerr…   Úloggerr   r'   r#   r!   Ú<module>r™      sw   ðß 6Ó 6ç kÕ kß 4ñ ×ÒÝ(ñ ×ÒÛ÷÷
 Ýà	×	Ò	˜HÓ	%€ñ Ñ,ÀÔFÓGôk˜hó kó Hòkr#   