ó
    qyüiüx  ã                   ó~  • S SK r S SKJrJr  S SKrS SKJr  S SKJr  S SKJ	r
  SSKJr  SSKJrJr  SS	KJrJrJr  SS
KJrJrJrJrJrJrJrJrJrJrJrJ r   SSK!J"r"J#r#  SSK$J%r%J&r&   " S S\"SS9r'\RP                  \RR                  4r*S\+S\+S\RX                  S\RZ                  4S jr.  S(S\/S\\0-  S-  4S jjr1S\RZ                  S\RZ                  4S jr2S r3  S)S\RZ                  S\4S\0\ Rj                  -  S\/S\\0-  S\44S  jjr6 S*S!\7\+\+4   S"\+S#\+S-  S$\+S\7\+\+4   4
S% jjr8\& " S& S'\5      5       r9S'/r:g)+é    N)ÚAnyÚOptional)Únn)Ú
read_image)Ú
functionalé   )ÚTorchvisionBackend)ÚBatchFeatureÚget_size_dict)Úcenter_to_corners_formatÚcorners_to_center_formatÚsafe_squeeze)ÚIMAGENET_DEFAULT_MEANÚIMAGENET_DEFAULT_STDÚAnnotationFormatÚAnnotationTypeÚChannelDimensionÚ
ImageInputÚPILImageResamplingÚSizeDictÚget_image_sizeÚ#get_image_size_for_max_height_widthÚget_max_height_widthÚvalidate_annotations)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringc                   ó4   • \ rS rSr% Sr\\-  \S'   \\S'   Sr	g)ÚYolosImageProcessorKwargsé$   a  
format (`str`, *optional*, defaults to `AnnotationFormat.COCO_DETECTION`):
    Data format of the annotations. One of "coco_detection" or "coco_panoptic".
do_convert_annotations (`bool`, *optional*, defaults to `True`):
    Controls whether to convert the annotations to the format expected by the YOLOS model. Converts the
    bounding boxes to the format `(center_x, center_y, width, height)` and in the range `[0, 1]`.
    Can be overridden by the `do_convert_annotations` parameter in the `preprocess` method.
ÚformatÚdo_convert_annotations© N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústrr   Ú__annotations__ÚboolÚ__static_attributes__r$   ó    Úm/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/models/yolos/image_processing_yolos.pyr    r    $   s   ‡ ñð Ð"Ñ"Ó"Ø Ö r.   r    F)ÚtotalÚheightÚwidthÚdeviceÚreturnc                 óú  •  SSK Jn  / nU  HŽ  nUR                  XaU5      nUR	                  U5      n[        UR                  5      S:  a  US   n[        R                  " U[        R                  US9n[        R                  " USS9nUR                  U5        M�     U(       a  [        R                  " USS9nU$ [        R                  " SX4[        R                  US9nU$ ! [         a    [        S5      ef = f)	a  
Convert a COCO polygon annotation to a mask.

Args:
    segmentations (`list[list[float]]`):
        List of polygons, each polygon represented by a list of x-y coordinates.
    height (`int`):
        Height of the mask.
    width (`int`):
        Width of the mask.
r   )Úmaskz1Pycocotools is not installed in your environment.r   ).N©Údtyper3   é   )Úaxis)Úpycocotoolsr6   ÚImportErrorÚfrPyObjectsÚdecodeÚlenÚshapeÚtorchÚ	as_tensorÚuint8ÚanyÚappendÚstackÚzeros)	Úsegmentationsr1   r2   r3   Ú	coco_maskÚmasksÚpolygonsÚrlesr6   s	            r/   Úconvert_coco_poly_to_maskrM   6   sæ   € ðOÝ1ð €EÛ!ˆØ×$Ñ$ X°uÓ=ˆØ×Ñ Ó%ˆÜˆt�z‰z‹?˜QÓØ˜	‘?ˆDÜ�Š˜t¬5¯;©;¸vÑFˆÜ�yŠy˜ AÑ&ˆØ�‰�TÖñ "ö Ü—’˜E¨Ñ*ˆð €Lô —’˜Q Ð.´e·k±kÈ&ÑQˆà€Løô# ó OÜÐMÓNÐNðOús   ‚C$ Ã$C:Úreturn_segmentation_masksÚinput_data_formatc                 ó$  • U R                  5       SS u  pEUS   n[        R                  " U/[        R                  U R                  S9nUS   n/ n/ n	/ n
/ nU Hl  nSU;  d  US   S:X  d  M  UR                  US   5        U	R                  US	   5        U
R                  US
   5        SU;   d  MX  UR                  US   5        Mn     [        R                  " U[        R                  U R                  S9n[        R                  " U	[        R                  U R                  S9n	[        R                  " U[        R                  U R                  S9n[        R                  " U
[        R                  U R                  S9R                  SS5      n
U
SS2SS24==   U
SS2SS24   -  ss'   U
SS2SSS24   R                  SUS9U
SS2SSS24'   U
SS2SSS24   R                  SUS9U
SS2SSS24'   U
SS2S4   U
SS2S4   :„  U
SS2S4   U
SS2S4   :„  -  nUXŽ   X®   Xž   XÞ   [        R                  " [        U5      [        U5      /[        R                  U R                  S9S.nU(       a_  [        R                  " U[        R                  U R                  S9nX¾   nUR                  S   nU(       a  UR                  S5      OUnX¿S'   U(       a1  U Vs/ s H  oÌS   PM	     nn[        UXEU R                  S9nUU   US'   U$ s  snf )zF
Convert the target in COCO format into the format expected by YOLOS.
éþÿÿÿNÚimage_idr7   ÚannotationsÚiscrowdr   Úcategory_idÚareaÚbboxÚ	keypointséÿÿÿÿé   r9   )ÚminÚmaxé   r   )rR   Úclass_labelsÚboxesrV   rT   Ú	orig_size)rY   r   Úsegmentation©r3   rJ   )ÚsizerA   rB   Úint64r3   rE   Úfloat32Ú
zeros_likeÚreshapeÚclipÚintr@   rM   )ÚimageÚtargetrN   rO   Úimage_heightÚimage_widthrR   rS   ÚclassesrV   r_   rX   ÚobjrT   ÚkeepÚ
new_targetÚnum_keypointsÚsegmentation_masksrJ   s                      r/   Ú!prepare_coco_detection_annotationrt   Y   sá  € ð !&§
¡
£¨R¨SÐ 1Ñ€Là�jÑ!€HÜ�Š ˜z´·±ÀUÇ\Á\ÑR€Hð ˜Ñ'€KØ€GØ€DØ€EØ€IÛˆØ˜CÓ 3 y¡>°QÕ#6Ø�N‰N˜3˜}Ñ-Ô.Ø�K‰K˜˜F™Ô$Ø�L‰L˜˜V™Ô%Ø˜cÕ!Ø× Ñ   [Ñ!1Ö2ñ ô �oŠo˜g¬U¯[©[ÀÇÁÑN€GÜ�?Š?˜4¤u§}¡}¸U¿\¹\ÑJ€DÜ×Ò˜w¬e¯k©kÀ%Ç,Á,ÑO€Gä�OŠO˜E¬¯©¸u¿|¹|ÑL×TÑTÐUWÐYZÓ[€EØ	Š!ˆQ‰Rˆ%ƒL�Eš!˜R˜a˜R˜%‘LÑ ƒLØš1˜a˜d ˜d˜7‘^×(Ñ(¨Q°KÐ(Ð@€EŠ!ˆQˆT�ˆTˆ'�NØš1˜a˜d ˜d˜7‘^×(Ñ(¨Q°LÐ(ÐA€EŠ!ˆQˆT�ˆTˆ'�Nà’!�Q�$‰K˜%¢ 1 ™+Ñ%¨%²°1°©+¸ºaÀ¸d¹Ñ*CÑD€Dð Ø™Ø‘Ø‘
Ø‘=Ü—_’_¤c¨,Ó&7¼¸[Ó9IÐ%JÔRW×R]ÑR]Ðfk×frÑfrÑsñ€Jö Ü—O’O I´U·]±]È5Ï<É<ÑXˆ	à‘Oˆ	Ø!Ÿ™¨Ñ*ˆÞ2?�I×%Ñ% gÔ.ÀYˆ	Ø"+�;Ñæ Ù=HÓIº[°c .Ô1¹[ÐÐIÜ)Ð*<¸lÐ`e×`lÑ`lÑmˆØ# D™kˆ
�7ÑàÐùò	 Js   ËLrJ   c           	      óš  • U R                  5       S:X  a  [        R                  " SU R                  S9$ U R                  SS u  p[        R
                  " SU[        R                  U R                  S9n[        R
                  " SU[        R                  U R                  S9n[        R                  " X4SS9u  p4U [        R                  " US5      -  nUR                  UR                  S   S	5      R                  S	5      S   n[        R                  " XR                  S5      [        R                  " S
U R                  S95      R                  U R                  S   S	5      R                  S	5      S   nU [        R                  " US5      -  nUR                  UR                  S   S	5      R                  S	5      S   n	[        R                  " XR                  S5      [        R                  " S
U R                  S95      R                  U R                  S   S	5      R                  S	5      S   n
[        R                  " XzXi/S5      $ )zÿ
Compute the bounding boxes around the provided panoptic segmentation masks.

Args:
    masks: masks in format `[number_masks, height, width]` where N is the number of masks

Returns:
    boxes: bounding boxes in format `[number_masks, 4]` in xyxy format
r   )r   rZ   rb   rQ   Nr7   Úij)ÚindexingrY   g    „×—Ar]   )ÚnumelrA   rG   r3   r@   Úarangere   ÚmeshgridÚ	unsqueezeÚviewr\   ÚwhereÚtensorr[   rF   )rJ   ÚhÚwÚyÚxÚx_maskÚx_maxÚx_minÚy_maskÚy_maxÚy_mins              r/   Úmasks_to_boxesr‰   ™   sÅ  € ð ‡{�{ƒ}˜ÓÜ�{Š{˜6¨%¯,©,Ñ7Ð7à�;‰;�r�sÐ�D€AÜ�Š�Q˜¤§¡°u·|±|ÑD€AÜ�Š�Q˜¤§¡°u·|±|ÑD€Aä�>Š>˜!¨Ñ.�D€Aà”U—_’_ Q¨Ó*Ñ*€FØ�K‰K˜Ÿ™ Q™¨Ó,×0Ñ0°Ó4°QÑ7€Eä�Š�EŸ;™; q›>¬5¯<ª<¸ÀEÇLÁLÑ+QÓR×WÑWÐX]×XcÑXcÐdeÑXfÐhjÓk×oÑoÐprÓsÐtuÑvð 
ð ”U—_’_ Q¨Ó*Ñ*€FØ�K‰K˜Ÿ™ Q™¨Ó,×0Ñ0°Ó4°QÑ7€Eä�Š�EŸ;™; q›>¬5¯<ª<¸ÀEÇLÁLÑ+QÓR×WÑWÐX]×XcÑXcÐdeÑXfÐhjÓk×oÑoÐprÓsÐtuÑvð 
ô �;Š;˜ eÐ3°QÓ7Ð7r.   c                 ó„  • [        U [        R                  5      (       a‚  [        U R                  5      S:X  ai  U R
                  [        R                  :X  a  U R                  [        R                  5      n U SS2SS2S4   SU SS2SS2S4   -  -   SU SS2SS2S4   -  -   $ [        U S   SU S   -  -   SU S   -  -   5      $ )z"
Converts RGB color to unique ID.
r   Nr   é   r]   i   r9   )
Ú
isinstancerA   ÚTensorr?   r@   r8   rC   ÚtoÚint32ri   )Úcolors    r/   Ú	rgb_to_idr‘   ¾   s©   € ô �%œŸ™×&Ñ&¬3¨u¯{©{Ó+;¸qÓ+@Ø�;‰;œ%Ÿ+™+Ó%Ø—H‘HœUŸ[™[Ó)ˆEØ’Qš˜1�W‰~  eªAªq°!¨G¡nÑ 4Ñ4°yÀ5ÊÊAÈqÈÁ>Ñ7QÑQÐQÜˆu�Q‰x˜#  a¡™.Ñ(¨9°u¸Q±xÑ+?Ñ?Ó@Ð@r.   rj   rk   Ú
masks_pathÚreturn_masksc                 ó  • [        XS9u  pV[        R                  " U5      US   -  n0 n[        R                  " SU;   a  US   OUS   /[        R
                  U R                  S9US'   [        R                  " XV/[        R
                  U R                  S9US'   [        R                  " XV/[        R
                  U R                  S9US'   SU;   Ga›  [        U5      R                  S	S
S5      R                  [        R                  U R                  S9n	[        U	5      n	[        R                  " US    V
s/ s H  oªS   PM	     sn
U R                  S9nX›SS2SS4   :H  n	U	R                  [        R                  5      n	U(       a  X˜S'   [        U	5      US'   [        R                  " US    V
s/ s H  oªS   PM	     sn
[        R
                  U R                  S9US'   [        R                  " US    V
s/ s H  oªS   PM	     sn
[        R
                  U R                  S9US'   [        R                  " US    V
s/ s H  oªS   PM	     sn
[        R                  U R                  S9US'   U$ s  sn
f s  sn
f s  sn
f s  sn
f )z/
Prepare a coco panoptic annotation for YOLOS.
)Úchannel_dimÚ	file_namerR   Úidr7   rc   r`   Úsegments_infor]   r9   r   rb   NrJ   r_   rU   r^   rT   rV   )r   ÚpathlibÚPathrA   rB   rd   r3   r   ÚpermuterŽ   r�   r‘   r,   r‰   re   )rj   rk   r’   r“   rO   rl   rm   Úannotation_pathrq   rJ   Úsegment_infoÚidss               r/   Ú prepare_coco_panoptic_annotationrŸ   É   sG  € ô !/¨uÑ TÑ€LÜ—l’l :Ó.°¸Ñ1DÑD€Oà€JÜ"Ÿ_š_Ø)¨VÓ3ˆ�
Ò	¸À¹ÐFÌeÏkÉkÐbg×bnÑbnñ€JˆzÑô Ÿš¨,Ð)DÌEÏKÉKÐ`e×`lÑ`lÑm€JˆvÑÜ#Ÿošo¨|Ð.IÔQV×Q\ÑQ\Ðej×eqÑeqÑr€Jˆ{Ñà˜&Ô Ü˜?Ó+×3Ñ3°A°q¸!Ó<×?Ñ?ÄeÇkÁkÐZ_×ZfÑZfÐ?ÐgˆÜ˜%Ó ˆä�oŠoÀfÈ_ÒF]Ó^ÒF]°l¨DÔ1ÑF]Ñ^Ðgl×gsÑgsÑtˆØšQ  d˜]Ñ+Ñ+ˆØ—‘œŸ™Ó$ˆÞØ"'�wÑÜ,¨UÓ3ˆ
�7ÑÜ%*§_¢_Ø=CÀOÒ=TÓUÒ=T¨\˜-Ô(Ñ=TÑUÜ—+‘+Ø—<‘<ñ&
ˆ
�>Ñ"ô
 !&§¢Ø9?ÀÒ9PÓQÒ9P¨˜)Ô$Ñ9PÑQÜ—+‘+Ø—<‘<ñ!
ˆ
�9Ñô
 #Ÿ_š_Ø6<¸_Ò6MÓNÒ6M l˜&Ô!Ñ6MÑNÜ—-‘-Ø—<‘<ñ
ˆ
�6Ñð Ðùò- _ùò Vùò
 Rùò
 Os   Ä9I2Æ2I7Ç9I<É JÚ
image_sizerc   Úmax_sizeÚmod_sizec                 óº  • U u  pESnUbP  [        [        XE45      5      n[        [        XE45      5      nX‡-  U-  U:”  a  X'-  U-  n[        [	        U5      5      nXT:  a*  Un	Ub  Ub  [        Xd-  U-  5      n
OQ[        X-  U-  5      n
O@XE::  a  XA:X  d
  XT::  a  XQ:X  a  XEpšO)Un
Ub  Ub  [        Xe-  U-  5      n	O[        X-  U-  5      n	Ub  X™U-  -
  n	XªU-  -
  n
X©4$ )a_  
Computes the output image size given the input image size and the desired output size, while ensuring that both
height and width are multiples of `mod_size`.

This mirrors the YOLOS-specific behavior used in the torch/fast backends and is required so that all YOLOS
image processing backends (PIL, torchvision, fast) produce identical output shapes.
N)Úfloatr[   r\   ri   Úround)r    rc   r¡   r¢   r1   r2   Úraw_sizeÚmin_original_sizeÚmax_original_sizeÚowÚohs              r/   Ú get_size_with_aspect_ratio_yolosr«   ú   s  € ð �M€FØ€HØÑÜ!¤# v oÓ"6Ó7ÐÜ!¤# v oÓ"6Ó7ÐØÑ0°4Ñ7¸(ÓBØÑ3Ð6GÑGˆHÜ”u˜X“Ó'ˆDàƒ~ØˆØÑ HÑ$8Ü�XÑ&¨Ñ.Ó/‰Bä�T‘] UÑ*Ó+‰BØ
‹/˜f›n°%³/ÀeÃmØ‰BàˆØÑ HÑ$8Ü�XÑ%¨Ñ.Ó/‰Bä�T‘\ FÑ*Ó+ˆBàÑØ˜‘=Ñ!ˆØ˜‘=Ñ!ˆàˆ8€Or.   c            $       óà  ^ • \ rS rSr\r\R                  r\	r
\r\R                  rSrSrSrSrSSS.rSrSS/rS	\\   S
S4U 4S jjr    S:S\R4                  S\S\S-  S\S-  S\\R>                  -  S-  S\\ -  S-  S
\4S jjr! S;S\R4                  S\"S\#S   S
\R4                  4U 4S jjjr$S\RJ                  4S\\\&4   S\'\(\(4   S\'\(\(4   S\)S\#S   4
U 4S jjjr*S\S\'\(\(4   S
\4S jr+S\S \'\(\(4   S!\'\(\(4   S
\4S" jr,   S<S\R4                  S#\'\(\(4   S\\\&4   S-  S$\S%\(4
S& jjr-\.   S=S'\/S(\0\1\0   -  S-  S\S-  S\\R>                  -  S-  S	\\   S
\24U 4S) jjj5       r3S'\1S*   S(\0\1\0   -  S-  S\S\\R>                  -  S-  S+\S\"SS,S-\S.\)S/\S0\S1\)\1\)   -  S-  S2\)\1\)   -  S-  S3\S4\"S-  S\\-  S-  S5\\4-  S-  S
\24$S6 jr5 S>S\)S7\4\1\'   -  4S8 jjr6S9r7U =r8$ )?ÚYolosImageProcessori#  Té   é5  ©Úshortest_edgeÚlongest_edgeFÚpixel_valuesÚ
pixel_maskÚkwargsr4   Nc                 ó�  >• UR                  SUR                  SU R                  5      5        UR                  SS 5      nUc  S OUR                  SS5      nUb  UOSSS.n[        X#SS	9US'   UR	                  S
5      nUR	                  S5      nUc$  [        U S
S 5      c  Ub  UOU R                  U l        [        TU ]$  " S0 UD6  g )NÚdo_padÚpad_and_return_pixel_maskrc   r¡   r¯   r®   r°   F)r¡   Údefault_to_squarer#   Údo_normalizer$   )
Ú
setdefaultÚpopr·   r   ÚgetÚgetattrrº   r#   ÚsuperÚ__init__)Úselfrµ   rc   r¡   r#   rº   Ú	__class__s         €r/   rÀ   ÚYolosImageProcessor.__init__2  sÈ   ø€ Ø×Ñ˜( F§J¡JÐ/JÈDÏKÉKÓ$XÔYà�z‰z˜& $Ó'ˆØ™<‘4¨V¯Z©Z¸
ÀDÓ-IˆØÑ'‰t¸sÐTXÑ-Yˆä& tÐRWÑXˆˆv‰ð "(§¡Ð,DÓ!EÐØ—z‘z .Ó1ˆØ!Ñ)¬g°dÐ<TÐVZÓ.[Ñ.cØ:FÑ:R©,ÐX\×XiÑXiˆDÔ'ä‰ÒÑ"˜6Ó"r.   rj   rk   r"   rN   r’   rO   c                 óä   • Ub  UOU R                   nU[        R                  :X  a  Uc  SOUn[        XXFS9nU$ U[        R                  :X  a  Uc  SOUn[        UUUUUS9nU$ [        SU S35      e)z5
Prepare an annotation for feeding into YOLOS model.
F)rO   T)r’   r“   rO   zFormat z is not supported.)r"   r   ÚCOCO_DETECTIONrt   ÚCOCO_PANOPTICrŸ   Ú
ValueError)rÁ   rj   rk   r"   rN   r’   rO   s          r/   Úprepare_annotationÚ&YolosImageProcessor.prepare_annotationC  sž   € ð "Ñ-‘°4·;±;ˆàÔ%×4Ñ4Ó4Ø1JÑ1R©ÐXqÐ%Ü6ØÐ8ñˆFð ˆð Ô'×5Ñ5Ó5Ø0IÑ0Q©ÐWpÐ%Ü5ØØØ%Ø6Ø"3ñˆFð ˆô ˜w v hÐ.@ÐAÓBÐBr.   rc   Úresamplez0PILImageResampling | tvF.InterpolationMode | intc                 ó$  >• UR                   (       a@  UR                  (       a/  [        UR                  SS UR                   UR                  5      nO›UR                  (       a@  UR
                  (       a/  [        UR                  SS UR                  UR
                  5      nOJUR                  (       a*  UR                  (       a  UR                  UR                  4nO[        SU S35      e[        TU ],  " U4[        US   US   S9US.UD6nU$ )	aË  
Resize the image to the given size. Size can be `min_size` (scalar) or `(height, width)` tuple. If size is an
int, smaller edge of the image will be matched to this number.

Args:
    image (`torch.Tensor`):
        Image to resize.
    size (`SizeDict`):
        Size of the image's `(height, width)` dimensions after resizing. Available options are:
            - `{"height": int, "width": int}`: The image will be resized to the exact size `(height, width)`.
                Do NOT keep the aspect ratio.
            - `{"shortest_edge": int, "longest_edge": int}`: The image will be resized to a maximum size respecting
                the aspect ratio and keeping the shortest edge less or equal to `shortest_edge` and the longest edge
                less or equal to `longest_edge`.
            - `{"max_height": int, "max_width": int}`: The image will be resized to the maximum size respecting the
                aspect ratio and keeping the height less or equal to `max_height` and the width less or equal to
                `max_width`.
    resample (`PILImageResampling | tvF.InterpolationMode | int`, *optional*, defaults to `PILImageResampling.BILINEAR`):
        Resampling filter to use if resizing the image.
rQ   Nz\Size must contain 'height' and 'width' keys or 'shortest_edge' and 'longest_edge' keys. Got Ú.r   r]   ©r1   r2   ©rc   rÊ   )r±   r²   r«   r@   Ú
max_heightÚ	max_widthr   r1   r2   rÇ   r¿   Úresizer   )rÁ   rj   rc   rÊ   rµ   Únew_sizerÂ   s         €r/   rÑ   ÚYolosImageProcessor.resizec  sæ   ø€ ð6 ×× $×"3×"3ô 8¸¿¹ÀBÀCÐ8HÈ$×J\ÑJ\Ð^b×^oÑ^oÓp‰HØ�_�_ §§Ü:¸5¿;¹;ÀrÀsÐ;KÈTÏ_É_Ð^b×^lÑ^lÓm‰HØ�[�[˜TŸZŸZØŸ™ T§Z¡ZÐ0‰HäØnÐosÐntÐtuÐvóð ô ‘’Øð
Ü ¨°©¸8ÀA¹;ÑGÐRZñ
Ø^dñ
ˆð ˆr.   ç      à?Ú
annotationr`   Útarget_sizeÚ	thresholdc                 ó~  >• [        X25       VVs/ s H	  u  pgXg-  PM     snnu  p‰0 n
X:S'   UR                  5        Hò  u  p¼US:X  a;  UnU[        R                  " X˜X˜/[        R                  UR
                  S9-  nXêS'   MF  US:X  a  UnXùU-  -  nUU
S'   M\  US:X  a€  USS2S4   nU Vs/ s H$  n[        [        U ]#  U[        US   US   S	9US
9PM&     nn[        R                  " U5      R                  [        R                  5      nUSS2S4   U:„  nUU
S'   Mâ  US:X  a  X:S'   Mî  XÊU'   Mô     U
$ s  snnf s  snf )ak  
Resizes an annotation to a target size.

Args:
    annotation (`dict[str, Any]`):
        The annotation dictionary.
    orig_size (`tuple[int, int]`):
        The original size of the input image.
    target_size (`tuple[int, int]`):
        The target size of the image, as returned by the preprocessing `resize` step.
    threshold (`float`, *optional*, defaults to 0.5):
        The threshold used to binarize the segmentation masks.
    resample (`PILImageResampling | tvF.InterpolationMode | int`, defaults to `tvF.InterpolationMode.NEAREST_EXACT`):
        The resampling filter to use when resizing the masks.
rc   r_   r7   rV   rJ   Nr   r]   rÍ   rÎ   )ÚzipÚitemsrA   rB   re   r3   r¿   r­   rÑ   r   rF   rŽ   )rÁ   rÕ   r`   rÖ   r×   rÊ   rk   ÚorigÚratio_heightÚratio_widthÚnew_annotationÚkeyÚvaluer_   Úscaled_boxesrV   Úscaled_arearJ   r6   rÂ   s                      €r/   Úresize_annotationÚ%YolosImageProcessor.resize_annotation�  s}  ø€ ô. HKÈ;ÔGbÔ$cÒGb±|°v V¤]ÑGbÒ$cÑ!ˆàˆØ!,�vÑà$×*Ñ*Ö,‰JˆCØ�g‹~Ø�Ø$¤u§¢Ø °ÐJÔRW×R_ÑR_Ðhm×htÑhtñ(ñ  �ð +7˜wÓ'Ø˜“Ø�Ø"°LÑ&@ÑA�Ø)4�˜vÓ&Ø˜“Øša ˜g™�ñ
 !&ó	ò !&˜ô Ô-¨tÑ;Ø¤8°;¸q±>ÈÐUVÉÑ#XÐckð <ó ñ !&ð	 ð ô Ÿš EÓ*×-Ñ-¬e¯m©mÓ<�Øša ˜d™ iÑ/�Ø*/�˜wÓ'Ø˜“Ø)4˜vÓ&à&+˜sÓ#ñ3 -ð6 ÐùóA %dùò$s   �D4Â++D:r    c                 óä   • Uu  p40 nUR                  5        HU  u  pgUS:X  aF  Un[        U5      nU[        R                  " XCXC/[        R                  UR
                  S9-  nX…U'   MQ  XuU'   MW     U$ )Nr_   r7   )rÚ   r   rA   rB   re   r3   )	rÁ   rÕ   r    rl   rm   Únorm_annotationrß   rà   r_   s	            r/   Únormalize_annotationÚ(YolosImageProcessor.normalize_annotationÉ  sƒ   € Ø$.Ñ!ˆØˆØ$×*Ñ*Ö,‰JˆCØ�g‹~Ø�Ü0°Ó7�ØœŸšØ °ÐJÔRW×R_ÑR_Ðhm×htÑhtññ �ð (- Ó$à', Ó$ñ -ð Ðr.   Úinput_image_sizeÚoutput_image_sizec                 ó^  • 0 nX6S'   S [        X25       5       u  pxUR                  5        H~  u  pšU	S:X  a*  U
n[        R                  " UUSS9n[	        US5      nX¶S'   M5  U	S:X  a3  U(       a,  U
nU[
        R                  " X‡X‡/UR                  S9-  nXÆS'   Mn  U	S:X  a  X6S'   Mz  X¦U	'   M€     U$ )	z+
Update the annotation for a padded image.
rc   c              3   ó.   #   • U  H  u  pX!-  v •  M     g 7f©Nr$   )Ú.0ÚoutputÚinputs      r/   Ú	<genexpr>ÚJYolosImageProcessor._update_annotation_for_padded_image.<locals>.<genexpr>å  s   é € Ð$rÒIq¹¸ U¦^ÒIqùs   ‚rJ   r   ©Úfillr]   r_   rb   )rÙ   rÚ   ÚtvFÚpadr   rA   rB   r3   )rÁ   rÕ   ré   rê   ÚpaddingÚupdate_bboxesrÞ   rÜ   rÝ   rß   rà   rJ   r_   s                r/   Ú#_update_annotation_for_padded_imageÚ7YolosImageProcessor._update_annotation_for_padded_imageØ  sÈ   € ð ˆØ!2�vÑÙ$rÌÐM^ÔIqÓ$rÑ!ˆà$×*Ñ*Ö,‰JˆCØ�g‹~Ø�ÜŸšØØØñ�ô
 % U¨AÓ.�Ø*/˜wÓ'Ø˜“¦MØ�ØœŸš¨+À[Ð)_Ðhm×htÑhtÑuÑu�Ø*/˜wÓ'Ø˜“Ø):˜vÓ&à&+˜sÓ#ñ# -ð$ Ðr.   Úpadded_sizerø   rô   c                 ó€  • UR                  5       SS  nUS   US   -
  nUS   US   -
  nUS:  d  US:  a  [        SU SU S35      eXb:w  a0  SSX‡/n	[        R                  " XUS9nUb  U R	                  X6X)U5      n[
        R                  " U[
        R                  UR                  S9n
SU
S US   2S US   24'   XU4$ )	NrQ   r   r]   zzPadding dimensions are negative. Please make sure that the padded size is larger than the original size. Got padded size: z, original size: rÌ   ró   r7   )	rc   rÇ   rõ   rö   rù   rA   rG   rd   r3   )rÁ   rj   rû   rÕ   rø   rô   Úoriginal_sizeÚpadding_bottomÚpadding_rightr÷   r´   s              r/   rö   ÚYolosImageProcessor.padû  s  € ð Ÿ
™
› R SÐ)ˆØ$ Q™¨-¸Ñ*:Ñ:ˆØ# A™¨°qÑ)9Ñ9ˆØ˜AÓ °Ó!2Üð3Ø3>°-Ð?PÐQ^ÐP_Ð_`ðbóð ð Ó'Ø˜!˜]Ð;ˆGÜ—G’G˜E°Ñ6ˆEØÑ%Ø!×EÑEØ¨{À]ó�
ô
 —[’[ ´E·K±KÈÏÉÑUˆ
Ø=>ˆ
Ð%�] 1Ñ%Ð%Ð'9¨°qÑ)9Ð'9Ð9Ñ:à *Ð,Ð,r.   ÚimagesrS   c                 ó(   >• [         TU ]  " XX440 UD6$ )a“  
annotations (`AnnotationType` or `list[AnnotationType]`, *optional*):
    Annotations to transform according to the padding that is applied to the images.
return_segmentation_masks (`bool`, *optional*, defaults to `self.return_segmentation_masks`):
    Whether to return segmentation masks.
masks_path (`str` or `pathlib.Path`, *optional*):
    Path to the directory containing the segmentation masks.
)r¿   Ú
preprocess)rÁ   r  rS   rN   r’   rµ   rÂ   s         €r/   r  ÚYolosImageProcessor.preprocess  s   ø€ ô" ‰wÒ! &Ð7PÑgÐ`fÑgÐgr.   ztorch.TensorÚ	do_resizez7PILImageResampling | tvF.InterpolationMode | int | NoneÚ
do_rescaleÚrescale_factorrº   r#   Ú
image_meanÚ	image_stdr·   Úpad_sizeÚreturn_tensorsc           
      ó  • Ub  [        U[        5      (       a  U/nUb<  [        U5      [        U5      :w  a$  [        S[        U5       S[        U5       S35      e[	        U5      nUb  [        U[        U5        UbQ  U[        R                  :X  a=  [        U[        R                  [        45      (       d  [        S[        U5       S35      e0 n/ n/ n/ n[        Xb  UOS/[        U5      -  5       Hä  u  nnUb"  U R                  UUUUU[        R                  S9nU(       aH  U R!                  UXgS9nUb3  U R#                  UUR%                  5       S	S UR%                  5       S	S S
9nUnU R'                  UX‰X¬U5      nU(       a-  Ub*  U R)                  U[+        U[        R                  5      5      nUR-                  U5        UR-                  U5        Mæ     UnUb  UOSnU(       GaB  Ub  UR.                  UR0                  4nO[3        U5      n/ n/ n[        Xb  UOS/[        U5      -  5       HÇ  u  nnUUR%                  5       S	S :X  aa  UR-                  U5        UR-                  [4        R6                  " U[4        R8                  UR:                  S95        UR-                  U5        M~  U R=                  UUUUS9u  nnnUR-                  U5        UR-                  U5        UR-                  U5        MÉ     UnUb  UOSnUR?                  S[4        R@                  " USS905        UR?                  S[4        R@                  " USS905        [C        UUS9nUb  U Vs/ s H  n[C        UUS9PM     snUS'   U$ s  snf )zO
Preprocess an image or a batch of images so that it can be used by the model.
NzThe number of images (z) and annotations (z) do not match.zxThe path to the directory containing the mask PNG files should be provided as a `pathlib.Path` or string object, but is z	 instead.)rN   r’   rO   rÎ   rQ   )r`   rÖ   r7   )rÕ   rø   r´   r   ©Údimr³   )Útensor_typeÚlabels)"rŒ   Údictr?   rÇ   r   r   ÚSUPPORTED_ANNOTATION_FORMATSrÆ   r™   rš   r*   ÚtyperÙ   rÈ   r   ÚFIRSTrÑ   rã   rc   Úrescale_and_normalizerç   r   rE   r1   r2   r   rA   Úonesrd   r3   rö   ÚupdaterF   r
   )rÁ   r  rS   rN   r’   r  rc   rÊ   r  r  rº   r#   r  r	  r·   r
  r"   r  rµ   ÚdataÚprocessed_imagesÚprocessed_annotationsÚpixel_masksrj   rÕ   Úresized_imagerû   Úpadded_imagesÚpadded_annotationsr´   Úencoded_inputss                                  r/   Ú_preprocessÚYolosImageProcessor._preprocess,  s­  € ð0 Ñ"¤z°+¼t×'DÑ'DØ&˜-ˆKàÑ"¤s¨6£{´c¸+Ó6FÓ'FÜØ(¬¨V«¨Ð5HÌÈ[ÓIYÐHZÐZiÐjóð ô " &Ó)ˆØÑ"Ü  Ô)EÀ{ÔSð Ñ"ØÔ*×8Ñ8Ó8Ü˜z¬G¯L©L¼#Ð+>×?Ñ?äð<Ü<@ÀÓ<LÐ;MÈYðXóð ð
 ˆàÐØ "ÐØˆÜ!$ VÑ<S©[ÐZ^ÐY_ÔbeÐflÓbmÑYmÖ!nÑˆE�:àÑ&Ø!×4Ñ4ØØØØ.GØ)Ü&6×&<Ñ&<ð 5ð �
ö Ø $§¡¨E¸ Ð P�ØÑ*Ø!%×!7Ñ!7Ø"Ø"'§*¡*£,¨r¨sÐ"3Ø$1×$6Ñ$6Ó$8¸¸Ð$=ð "8ð "�Jð
 &�à×.Ñ.¨u°jÐR^ÐluÓvˆEÞ%¨+Ñ*AØ!×6Ñ6°zÄ>ÐRWÔYi×YoÑYoÓCpÓq�
à×#Ñ# EÔ*Ø!×(Ñ(¨Ö4ñ7 "oð8 "ˆØ/:Ñ/FÑ+ÈDˆçàÑ#Ø'Ÿ™°·±Ð?‘ä2°6Ó:�àˆMØ!#ÐÜ%(¨Ñ@W±Ð^bÐ]cÔfiÐjpÓfqÑ]qÖ%rÑ!��zà %§*¡*£,¨r¨sÐ"3Ó3Ø!×(Ñ(¨Ô/Ø×&Ñ&¤u§z¢z°+ÄUÇ[Á[ÐY^×YeÑYeÑ'fÔgØ&×-Ñ-¨jÔ9ÙØ04·±Ø˜;°:ÐMcð 19ð 1Ñ-��z :ð ×$Ñ$ UÔ+Ø"×)Ñ)¨*Ô5Ø×"Ñ" :Ö.ñ &sð #ˆFØ0;Ñ0GÑ,ÈTˆKØ�K‰K˜¤u§{¢{°;ÀAÑ'FÐGÔHà�‰�^¤U§[¢[°¸QÑ%?Ð@ÔAÜ% d¸ÑGˆØÑ"áWbó(ÚWbÈ”˜Z°^ÔDÑWbñ(ˆN˜8Ñ$ð Ðùò(s   Í%NÚtarget_sizesc                 ó  • UR                   UR                  pTUb#  [        U5      [        U5      :w  a  [        S5      e[        R
                  R                  US5      nUSSS24   R                  S5      u  px[        U5      n	Ub¹  [        U[        5      (       aS  [        R                  " U V
s/ s H  oªS   PM	     sn
5      n[        R                  " U V
s/ s H  oªS   PM	     sn
5      nOUR                  S5      u  p¼[        R                  " XËXË/SS9R                  U	R                   5      nX�SS2SSS24   -  n	/ n[#        XxU	5       H1  u  nnnXÿU:„     nUXò:„     nUXò:„     nUR%                  UUUS.5        M3     U$ s  sn
f s  sn
f )	a!  
Converts the raw output of [`YolosForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format. Only supports PyTorch.

Args:
    outputs ([`YolosObjectDetectionOutput`]):
        Raw outputs of the model.
    threshold (`float`, *optional*):
        Score threshold to keep object detection predictions.
    target_sizes (`torch.Tensor` or `list[tuple[int, int]]`, *optional*):
        Tensor of shape `(batch_size, 2)` or list of tuples (`tuple[int, int]`) containing the target size
        `(height, width)` of each image in the batch. If unset, predictions will not be resized.
Returns:
    `list[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
    in the batch as predicted by the model.
NzTMake sure that you pass in as many target sizes as the batch dimension of the logitsrY   .r   r]   r  )Úscoresr  r_   )ÚlogitsÚ
pred_boxesr?   rÇ   r   r   Úsoftmaxr\   r   rŒ   ÚlistrA   r�   ÚunbindrF   rŽ   r3   rÙ   rE   )rÁ   Úoutputsr×   r"  Ú
out_logitsÚout_bboxÚprobr$  r  r_   ÚiÚimg_hÚimg_wÚ	scale_fctÚresultsÚsÚlÚbÚscoreÚlabelÚboxs                        r/   Úpost_process_object_detectionÚ1YolosImageProcessor.post_process_object_detection   s}  € ð&  'Ÿ~™~¨w×/AÑ/A�HàÑ#Ü�:‹¤# lÓ"3Ó3Ü Øjóð ô �}‰}×$Ñ$ Z°Ó4ˆØ˜c 3 B 3˜h™×+Ñ+¨BÓ/‰ˆô )¨Ó2ˆð Ñ#Ü˜,¬×-Ñ-ÜŸš±LÓ%A²L¨q¨¤d±LÑ%AÓB�ÜŸš±LÓ%A²L¨q¨¤d±LÑ%AÓB‘à+×2Ñ2°1Ó5‘�äŸš U°5Ð$@ÀaÑH×KÑKÈEÏLÉLÓYˆIØ¢a¨ªq jÑ1Ñ1ˆEàˆÜ˜6¨5Ö1‰GˆAˆq�!Ø˜)‘mÑ$ˆEØ�a‘mÑ$ˆEØ�A‘MÑ"ˆCØ�N‰N e°uÀsÑKÖLñ	 2ð ˆùò &BùÚ%As   Â/FÃF	)r#   )NNNNrí   )NTr   )NNN)rÔ   N)9r%   r&   r'   r(   r    Úvalid_kwargsr   ÚBILINEARrÊ   r   r  r   r	  r   rÅ   r"   r  r  rº   r·   rc   r¹   Úmodel_input_namesr   rÀ   rA   r�   r  r,   r*   r™   rš   r   rÈ   r   r   rÑ   ÚNEARESTr   Útupleri   r¤   rã   rç   rù   rö   r   r   r   r(  r
   r  r   r   r9  r-   Ú__classcell__)rÂ   s   @r/   r­   r­   #  s*  ø† à,€LØ!×*Ñ*€HØ&€JØ$€IØ×,Ñ,€FØ€IØ€JØ€LØ€FØ °$Ñ7€DØÐØ'¨Ð6Ðð# Ð(AÑ!Bð #Àt÷ #ð* +/Ø15Ø04Ø;?ñà�|‰|ðð ðð ! 4Ñ'ð	ð
 $(¨$¡;ðð ˜'Ÿ,™,Ñ&¨Ñ-ðð Ð!1Ñ1°DÑ8ðð 
õðH RVñ	+à�|‰|ð+ð ð+ð ÐMÑNð	+ð 
�‰÷+ð +ðd ØQc×QkÑQkñ7à˜˜c˜‘Nð7ð ˜˜c˜‘?ð7ð ˜3 ˜8‘_ð	7ð
 ð7ð ÐMÑN÷7ð 7ðr¨tð ÀÀsÈCÀxÁð ÐUYô ð!àð!ð    S ™/ð!ð !  c ™?ð	!ð 
ô!ðN -1Ø"Øñ-à�|‰|ð-ð ˜3 ˜8‘_ð-ð ˜˜c˜‘N TÑ)ð	-ð
 ð-ð õ-ð< ð EIØ15Ø04ñhàðhð $ d¨>Ñ&:Ñ:¸TÑAðhð $(¨$¡;ð	hð
 ˜'Ÿ,™,Ñ&¨Ñ-ðhð Ð2Ñ3ðhð 
÷hó ðhð$rà�^Ñ$ðrð $ d¨>Ñ&:Ñ:¸TÑAðrð $(ð	rð
 ˜'Ÿ,™,Ñ&¨Ñ-ðrð ðrð ðrð Lðrð ðrð ðrð ðrð !%ðrð ˜D ™KÑ'¨$Ñ.ðrð ˜4 ™;Ñ&¨Ñ-ðrð ðrð  ˜T‘/ð!rð" Ð&Ñ&¨Ñ-ð#rð$ ˜jÑ(¨4Ñ/ð%rð( 
ô)rðj Y]ñ3Ø"'ð3Ø=GÈ$ÈuÉ+Ñ=U÷3ó 3r.   r­   )FN)TN)Né   );r™   Útypingr   r   rA   r   Útorchvision.ior   Útorchvision.transforms.v2r   rõ   Úimage_processing_backendsr	   Úimage_processing_utilsr
   r   Úimage_transformsr   r   r   Úimage_utilsr   r   r   r   r   r   r   r   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r    rÅ   rÆ   r  ri   r3   r�   rM   r,   r*   rt   r‰   r‘   r  rš   rŸ   r?  r«   r­   Ú__all__r$   r.   r/   Ú<module>rL     s¯  ðó ß  ã Ý Ý %Ý 7å ;ß Aß `Ñ `÷÷ ÷ ó ÷ 5ß /ô! °Eò !ð !1× ?Ñ ?ÐAQ×A_ÑA_Ð`Ð ð°Sð Àð ÈeÏlÉlð Ð_d×_kÑ_kô ðL ',Ø7;ñ	=ð  $ð=ð (¨#Ñ-°Ñ4õ	=ð@8˜%Ÿ,™,ð 8¨5¯<©<ô 8òJAð Ø04ñ.Ø�<‰<ð.àð.ð �g—l‘lÑ"ð.ð ð	.ð
 (¨#Ñ-ð.ð 
õ.ðd Z\ñ&Ø�c˜3�h‘ð&Ø'*ð&Ø69¸D±jð&ØSVð&à
ˆ3�ˆ8�_õ&ðR ôoÐ,ó oó ðoðd !Ð
!�r.   