+
    QV-j&  ã                   ó  € ^ RI HtHtHt ^ RI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 ]! 4       '       d   ^RIHtHtHtHt ]
P0                  ! ]4      t]! ]! RR	7      4       ! R
 R]4      4       tR# )é    )ÚAnyÚUnionÚoverloadN)Úadd_end_docstringsÚis_torch_availableÚis_vision_availableÚloggingÚrequires_backends)ÚPipelineÚbuild_pipeline_init_args)ÚImage)Ú
load_image)Ú*MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMESÚ-MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMESÚ-MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMESÚ.MODEL_FOR_UNIVERSAL_SEGMENTATION_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	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RtVtV ;t# )ÚImageSegmentationPipelineat  
Image segmentation pipeline using any `AutoModelForXXXSegmentation`. This pipeline predicts masks of objects and
their classes.

Example:

```python
>>> from transformers import pipeline

>>> segmenter = pipeline(model="facebook/detr-resnet-50-panoptic")
>>> segments = segmenter("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")
>>> len(segments)
2

>>> segments[0]["label"]
'bird'

>>> segments[1]["label"]
'bird'

>>> type(segments[0]["mask"])  # This is a black and white mask showing where is the bird on the original image.
<class 'PIL.Image.Image'>

>>> segments[0]["mask"].size
(768, 512)
```


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

See the list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=image-segmentation).
FTNc                ó
  <€ \         SV `  ! V/ VB  \        V R 4       \        P                  ! 4       pVP                  \        4       VP                  \        4       VP                  \        4       V P                  V4       R# )ÚvisionN)
ÚsuperÚ__init__r
   r   ÚcopyÚupdater   r   r   Úcheck_model_type)ÚselfÚargsÚkwargsÚmappingÚ	__class__s   &*, €Úz/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/pipelines/image_segmentation.pyr   Ú"ImageSegmentationPipeline.__init__D   sb   ø€ Ü‰Ò˜$Ð) &Ò)ä˜$ Ô)Ü<×AÒAÓCˆØ�‰ÔDÔEØ�‰ÔDÔEØ�‰ÔEÔFØ×Ñ˜gÖ&ó    c                óê   € / p/ pR V9   d   VR ,          VR &   VR ,          VR &   RV9   d   VR,          VR&   RV9   d   VR,          VR&   RV9   d   VR,          VR&   RV9   d   VR,          VR&   V/ V3# )ÚsubtaskÚ	thresholdÚmask_thresholdÚoverlap_mask_area_thresholdÚtimeout© )r   r   Úpreprocess_kwargsÚpostprocess_kwargss   &,  r"   Ú_sanitize_parametersÚ.ImageSegmentationPipeline._sanitize_parametersN   s¨   € ØÐØÐØ˜ÔØ,2°9Õ,=Ð˜yÑ)Ø+1°)Õ+<Ð˜iÑ(Ø˜&Ô Ø.4°[Õ.AÐ˜{Ñ+Ø˜vÔ%Ø39Ð:JÕ3KÐÐ/Ñ0Ø(¨FÔ2Ø@FÐGdÕ@eÐÐ<Ñ=Ø˜ÔØ+1°)Õ+<Ð˜iÑ(à  "Ð&8Ð8Ð8r$   c          	      óf   <€ V ^8„  d   QhRS[ S[R3,          RS[RS[S[S[S[3,          ,          /# ©é   ÚinputszImage.Imager   Úreturn)r   Ústrr   ÚlistÚdict)ÚformatÚ__classdict__s   "€r"   Ú__annotate__Ú&ImageSegmentationPipeline.__annotate__`   s4   ø€ ×eÑe™u¡S¨-Ð%7Õ8ÐeÁCÐeÉDÑQUÑVYÑ[^ÐV^ÕQ_ÕL`Ñer$   c                ó   € R # ©Nr+   ©r   r3   r   s   &&,r"   Ú__call__Ú"ImageSegmentationPipeline.__call___   s   € Ùber$   c          
      ó�   <€ V ^8„  d   QhRS[ S[,          S[ R,          ,          RS[RS[ S[ S[S[S[3,          ,          ,          /# r1   )r6   r5   r   r7   )r8   r9   s   "€r"   r:   r;   c   s?   ø€ ×qÑq™t¡C�y©4°Õ+>Õ>ÐqÉ#ÐqÑRVÑW[Ñ\`ÑadÑfiÐaiÕ\jÕWkÕRlÑqr$   c                ó   € R # r=   r+   r>   s   &&,r"   r?   r@   b   s   € Ùnqr$   c                óÒ   <€ V ^8„  d   QhRS[ S[RS[S[,          S[R,          3,          RS[RS[S[S[S[3,          ,          S[S[S[S[S[3,          ,          ,          ,          /# r1   )r   r5   r6   r   r7   )r8   r9   s   "€r"   r:   r;   e   s`   ø€ ÷ 02ñ 02Ù™C ±±Sµ	¹4ÀÕ;NÐNÕOð02Ù[^ð02á	‰d‘3™�8�nÕ	¡¡T©$©s±C¨x­.Õ%9Õ :Õ	:ñ02r$   c                ót   <€ RV9   d   VP                  R4      pVf   \        R4      h\        SV `  ! V3/ VB # )a¡  
Perform segmentation (detect masks & 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.
    subtask (`str`, *optional*):
        Segmentation task to be performed, choose [`semantic`, `instance` and `panoptic`] depending on model
        capabilities. If not set, the pipeline will attempt tp resolve in the following order:
          `panoptic`, `instance`, `semantic`.
    threshold (`float`, *optional*, defaults to 0.9):
        Probability threshold to filter out predicted masks.
    mask_threshold (`float`, *optional*, defaults to 0.5):
        Threshold to use when turning the predicted masks into binary values.
    overlap_mask_area_threshold (`float`, *optional*, defaults to 0.5):
        Mask overlap threshold to eliminate small, disconnected segments.
    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:
    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 mask, label and score (where applicable) of each detected object and contains
    the following keys:

    - **label** (`str`) -- The class label identified by the model.
    - **mask** (`PIL.Image`) -- A binary mask of the detected object as a Pil Image of shape (width, height) of
      the original image. Returns a mask filled with zeros if no object is found.
    - **score** (*optional* `float`) -- Optionally, when the model is capable of estimating a confidence of the
      "object" described by the label and the mask.
ÚimageszICannot call the image-classification pipeline without an inputs argument!)ÚpopÚ
ValueErrorr   r?   )r   r3   r   r!   s   &&,€r"   r?   r@   e   sB   ø€ ðX �vÔØ—Z‘Z Ó)ˆFØŠ>ÜÐhÓiÐiÜ‰wÒ Ñ1¨&Ñ1Ð1r$   c                ó  € \        WR 7      pVP                  VP                  3.pV P                  P                  P
                  P                  R8X  d„   Vf   / pMRV./pV P                  ! RRV.RR/VB pVP                  V P                  4      pV P                  VR,          RV P                  P                  P                  RR7      R,          VR&   M/V P                  V.RR	7      pVP                  V P                  4      pWFR
&   V# ))r*   ÚOneFormerConfigÚtask_inputsrE   Úreturn_tensorsÚptÚ
max_length)ÚpaddingrM   rK   Ú	input_ids)rE   rK   Útarget_sizer+   )r   ÚheightÚwidthÚmodelÚconfigr!   Ú__name__Úimage_processorÚtoÚdtypeÚ	tokenizerÚtask_seq_len)r   Úimager&   r*   rP   r   r3   s   &&&&   r"   Ú
preprocessÚ$ImageSegmentationPipeline.preprocess—   s  € Ü˜5Ô2ˆØŸ™ e§k¡kÐ2Ð3ˆØ�:‰:×Ñ×&Ñ&×/Ñ/Ð3DÔDØŠØ‘à'¨'¨Ð3�Ø×)Ò)ÑX°%°ÐXÈÐXÐQWÑXˆFØ—Y‘Y˜tŸz™zÓ*ˆFØ$(§N¡NØ�}Õ%Ø$ØŸ:™:×,Ñ,×9Ñ9Ø#ð	 %3ó %ð
 õ%ˆF�=Ò!ð ×)Ñ)°%°ÈÐ)ÓNˆFØ—Y‘Y˜tŸz™zÓ*ˆFØ +ˆ}ÑØˆr$   c                óT   € VP                  R 4      pV P                  ! R/ VB pW#R &   V# )rP   r+   )rF   rS   )r   Úmodel_inputsrP   Úmodel_outputss   &&  r"   Ú_forwardÚ"ImageSegmentationPipeline._forward­   s1   € Ø"×&Ñ& }Ó5ˆØŸ
š
Ñ2 \Ñ2ˆØ'2�mÑ$ØÐr$   c           	     óî  € R pVR9   d4   \        V P                  R4      '       d   V P                  P                  pM9VR9   d3   \        V P                  R4      '       d   V P                  P                  pVeÜ   V! VVVVVR,          R7      ^ ,          p. pVR,          p	VR,           F¦  p
WšR,          8H  ^ÿ,          p\        P
                  ! VP                  4       P                  \        P                  4      RR	7      pV P                  P                  P                  V
R
,          ,          pV
R,          pVP                  RVRVRV/4       K¨  	  V# VR9   dø   \        V P                  R4      '       dÜ   V P                  P                  WR,          R7      ^ ,          p. pVP                  4       p	\        P                  ! V	4      pV F�  pWœ8H  ^ÿ,          p\        P
                  ! VP                  \        P                  4      RR	7      pV P                  P                  P                  V,          pVP                  RR RVRV/4       Kƒ  	  V# \!        RV R\#        V P                  4       24      h)NÚ"post_process_panoptic_segmentationÚ"post_process_instance_segmentationrP   )r'   r(   r)   Útarget_sizesÚsegmentationÚsegments_infoÚidÚL)ÚmodeÚlabel_idÚscoreÚlabelÚmaskÚ"post_process_semantic_segmentation)rf   zSubtask z is not supported for model >   NÚpanoptic>   NÚinstance>   NÚsemantic)ÚhasattrrV   rd   re   r   Ú	fromarrayÚnumpyÚastypeÚnpÚuint8rS   rT   Úid2labelÚappendrp   ÚuniquerG   Útype)r   r`   r&   r'   r(   r)   ÚfnÚoutputsÚ
annotationrg   Úsegmentro   rn   rm   Úlabelss   &&&&&&         r"   ÚpostprocessÚ%ImageSegmentationPipeline.postprocess³   s8  € ð ˆØÐ(Ô(¬W°T×5IÑ5IÐKo×-pÒ-pØ×%Ñ%×HÑH‰BØÐ*Ô*¬w°t×7KÑ7KÐMq×/rÒ/rØ×%Ñ%×HÑHˆBàŠ>ÙØØ#Ø-Ø,GØ*¨=Õ9ôð õˆGð ˆJØ" >Õ2ˆLà" ?×3Ð3�Ø$°­Ñ5¸Õ<�Ü—’ t§z¡z£|×':Ñ':¼2¿8¹8Ó'DÈ3ÔO�ØŸ
™
×)Ñ)×2Ñ2°7¸:Õ3FÕG�Ø Õ(�Ø×!Ñ! 7¨E°7¸EÀ6È4Ð"PÖQñ 4ð. Ðð! Ð*Ô*¬w°t×7KÑ7KÐMq×/rÒ/rØ×*Ñ*×MÑMØ¸-Õ,Hð Nó àõˆGð ˆJØ"Ÿ=™=›?ˆLÜ—Y’Y˜|Ó,ˆFã�Ø$Ñ-°Õ4�Ü—’ t§{¡{´2·8±8Ó'<À3ÔG�ØŸ
™
×)Ñ)×2Ñ2°5Õ9�Ø×!Ñ! 7¨D°'¸5À&È$Ð"OÖPñ	  ð Ðô ˜x¨ yÐ0LÌTÐRV×R\ÑR\ÓM]ÐL^Ð_Ó`Ð`r$   r+   )NN)NgÍÌÌÌÌÌì?ç      à?r…   )rU   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   r.   r   r?   r\   ra   rƒ   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r!   r9   s   @@r"   r   r      sj   ù‡ € ñ!ðF €OØ ÐØ#ÐØ€Oõ'ò9ð" ßeó Øeàßqó Øq÷02ó 02ôdò,÷,ô ,r$   r   )Útypingr   r   r   rv   rx   Úutilsr   r   r   r	   r
   Úbaser   r   ÚPILr   Úimage_utilsr   Úmodels.auto.modeling_autor   r   r   r   Ú
get_loggerrU   Úloggerr   r+   r$   r"   Ú<module>r™      sw   ðß 'Ñ 'ã ç kÕ kß 4ñ ×ÒÝå(á×Ò÷ó ð 
×	Ò	˜HÓ	%€ñ Ñ,ÀÔFÓGôD ó Dó HòDr$   