+
    œ°³jäV  ã                   óÆ  € R t ^ RIt^ RIt^ RIHtHt ^ RIt^ RIt^ RI	H
t ^RIHt ^RIHt ^RIHtHt ^RIHtHtHtHtHtHt ^RIHtHt ^R	IHtHtH t H!t!H"t" ] ! 4       '       d   ^ R
I#H$t$ ^ RI%H&t&H't' ]'       d   ^RI(H)t) ]!PT                  ! ]+4      t, ! R R]RR7      t-R R R llt.R R lt/R t0R R lt1R!R R llt2R R lt3R R lt4] ! R R]4      4       t5R.t6R# )"z"Image processor class for VitPose.N)ÚTYPE_CHECKINGÚUnion)Ú
functional)ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)ÚIMAGENET_DEFAULT_MEANÚIMAGENET_DEFAULT_STDÚChannelDimensionÚ
ImageInputÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringÚis_scipy_availableÚloggingÚrequires_backends)Úinv)Úaffine_transformÚgaussian_filter)ÚVitPoseEstimatorOutputc                   ó0   a € ] tR t^7t o RtV 3R ltRtV tR# )ÚVitPoseImageProcessorKwargsa5  
do_affine_transform (`bool`, *optional*):
    Whether to apply an affine transformation to the input images based on the bounding boxes.
normalize_factor (`float`, *optional*, defaults to `200.0`):
    Width and height scale factor used for normalization when computing center and scale from bounding boxes.
c                óN   <€ V ^8„  d   Qh/ S[ R,          ;R&   S[R,          ;R&   # )é   NÚdo_affine_transformÚnormalize_factor)ÚboolÚfloat)ÚformatÚ__classdict__s   "€Úu/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/vitpose/image_processing_vitpose.pyÚ__annotate__Ú(VitPoseImageProcessorKwargs.__annotate__7   s'   ø‡ ‚ ñ  �Ñ$ñ ñ ˜d•lÑ"ò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r#   s   @r$   r   r   7   s   ø‡ € ñ÷ ƒ r'   r   F)Útotalc          
      ó”   € V ^8„  d   QhR\         \        ,          \        P                  ,          R\        R\        R\
        R\
        /# )r   ÚboxÚimage_widthÚimage_heightr   Úpadding_factor)ÚtupleÚlistÚnpÚndarrayÚintr!   )r"   s   "r$   r%   r%   D   sG   € ÷ )ñ )Ü	”�œŸ
™
Õ	"ð)äð)ô ð)ô ð	)ô
 ñ)r'   c                ó’  € V R,          w  rVrxW,          p	\         P                  ! WWR,          ,           WhR,          ,           .\         P                  R7      p
WyV,          8”  d   VR,          V	,          pMWyV,          8  d	   W‰,          p\         P                  ! Ws,          Wƒ,          .\         P                  R7      pW´,          pW«3# )aa  
Encodes a bounding box in COCO format into (center, scale).

Args:
    box (`Tuple`, `List`, or `np.ndarray`):
        Bounding box in COCO format (top_left_x, top_left_y, width, height).
    image_width (`int`):
        Image width.
    image_height (`int`):
        Image height.
    normalize_factor (`float`):
        Width and height scale factor.
    padding_factor (`float`):
        Bounding box padding factor.

Returns:
    tuple: A tuple containing center and scale.

    - `np.ndarray` [float32](2,): Center of the bbox (x, y).
    - `np.ndarray` [float32](2,): Scale of the bbox width & height.
:Né   Nç      à?©Údtypeç      ð?)r9   ÚarrayÚfloat32)r3   r4   r5   r   r6   Ú
top_left_xÚ
top_left_yÚwidthÚheightÚaspect_ratioÚcenterÚscales   &&&&&       r$   Úbox_to_center_and_scalerK   D   s¢   € ð: -0°­GÑ)€J˜EØÕ-€LÜ�XŠX�z¨C¥KÕ/°Às½lÕ1JÐKÔSU×S]ÑS]Ô^€Fà˜fÕ$Ô$Ø˜•˜|Õ+‰Ø	 Õ&Ô	&ØÕ%ˆä�HŠH�eÕ.°Õ0IÐJÔRT×R\ÑR\Ô]€EØÕ"€Eàˆ=Ðr'   c                ó„   € V ^8„  d   QhR\         R\        P                  R\        P                  R\        P                  /# )r   ÚthetaÚ
size_inputÚsize_dstÚsize_target)r!   r9   r:   )r"   s   "r$   r%   r%   p   s7   € ÷ "ñ "œ5ð "¬b¯j©jð "ÄBÇJÁJð "Ô]_×]gÑ]gñ "r'   c                óÄ  € \         P                  ! V 4      p \         P                  ! R\         P                  R7      pV^ ,          V^ ,          ,          pV^,          V^,          ,          p\        P
                  ! V 4      V,          VR&   \        P                  ! V 4      ) V,          VR&   VRV^ ,          ,          \        P
                  ! V 4      ,          RV^,          ,          \        P                  ! V 4      ,          ,           RV^ ,          ,          ,           ,          VR&   \        P                  ! V 4      V,          VR&   \        P
                  ! V 4      V,          VR	&   VRV^ ,          ,          \        P                  ! V 4      ,          RV^,          ,          \        P
                  ! V 4      ,          ,
          RV^,          ,          ,           ,          VR
&   V# )aŒ  
Calculate the transformation matrix under the constraint of unbiased. Paper ref: Huang et al. The Devil is in the
Details: Delving into Unbiased Data Processing for Human Pose Estimation (CVPR 2020).

Source: https://github.com/open-mmlab/mmpose/blob/master/mmpose/core/post_processing/post_transforms.py

Args:
    theta (`float`):
        Rotation angle in degrees.
    size_input (`np.ndarray`):
        Size of input image [width, height].
    size_dst (`np.ndarray`):
        Size of output image [width, height].
    size_target (`np.ndarray`):
        Size of ROI in input plane [w, h].

Returns:
    `np.ndarray`: A matrix for transformation.
r?   r>   )r   é   ©é    rT   ©rT   é   g      à¿©rT   r   ©rV   rT   ©rV   rV   ©rV   r   )r9   Údeg2radÚzerosrC   ÚmathÚcosÚsin)rM   rN   rO   rP   ÚmatrixÚscale_xÚscale_ys   &&&&   r$   Úget_warp_matrixrc   p   sX  € ô( �JŠJ�uÓ€EÜ�XŠX�f¤B§J¡JÔ/€FØ�q�k˜K¨�NÕ*€GØ�q�k˜K¨�NÕ*€GÜ—8’8˜E“? WÕ,€Fˆ4�LÜ—H’H˜U“OÐ# gÕ-€Fˆ4�LØØˆz˜!�}ÕœtŸxšx¨›Õ.°°zÀ!µ}Õ1DÄtÇxÂxÐPUÃÕ1VÕVÐY\Ð_jÐklÕ_mÕYmÕmõ€Fˆ4�Lô —8’8˜E“? WÕ,€Fˆ4�LÜ—8’8˜E“? WÕ,€Fˆ4�LØØˆz˜!�}ÕœtŸxšx¨›Õ.°°zÀ!µ}Õ1DÄtÇxÂxÐPUÃÕ1VÕVÐY\Ð_jÐklÕ_mÕYmÕmõ€Fˆ4�Lð €Mr'   c           
     óÊ  € \        V P                  R,          4       Uu. uF  q0RV3,          NK  	  pp\        P                  ! V. RO.4      p\	        V4      pVR,          VR,          VR,          VR	,          VR
,          VR,          3w  VR	&   VR&   VR&   VR&   VR&   VR
&   V Uu. uF  p\        WvV^R7      NK  	  pp\        P                  ! VRR7      pV# u upi u upi )aO  
This function implements cv2.warpAffine function using affine_transform in scipy. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html and https://docs.opencv.org/4.x/d4/d61/tutorial_warp_affine.html for more details.

Note: the original implementation of cv2.warpAffine uses cv2.INTER_LINEAR.
.)Úoutput_shapeÚorder©Úaxiséÿÿÿÿ)rT   rT   rV   rY   rX   rU   rS   rZ   rW   )ÚrangeÚshaper9   Úvstackr   r   Ústack)	ÚsrcÚMÚsizeÚiÚchannelsÚM_scipyÚM_invÚchannelÚnew_srcs	   &&&      r$   Úscipy_warp_affinerw   •   sè   € ô &+¨3¯9©9°R­=Ô%9Ó:Ñ%9 �C˜�F—�Ñ%9€HÐ:ô �iŠi˜šI˜Ó'€Gä�‹L€Eàˆd�Øˆd�Øˆd�Øˆd�Øˆd�Øˆd�ðTÑP€Eˆ$�K��t‘˜e D™k¨5°©;¸¸d¹ÀUÈ4Á[ñ \dÓdÑ[cÐPWÔ ¸TÈ×KÑ[c€GÐdÜ�hŠh�w RÔ(€GØ€Nùò# ;ùò es   ŸCÂ(C c                óŽ   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  3,          /# )r   ÚheatmapsÚreturn)r9   r:   r7   )r"   s   "r$   r%   r%   ¯   s0   € ÷ ñ ¤r§z¡zð ´e¼B¿J¹JÌÏ
É
Ð<RÕ6Sñ r'   c                óŽ  € \        V \        P                  4      '       g   \        R4      hV P                  ^8w  d   \        R4      hV P                  w  rr4V P                  WR34      p\        P                  ! V^4      P                  W^34      p\        P                  ! V^4      P                  W^34      p\        P                  ! VR4      P                  \        P                  4      pVR,          V,          VR&   VR,          V,          VR&   \        P                  ! \        P                  ! VR4      R8„  VR4      pW‡3# )aÄ  Get keypoint predictions from score maps.

Args:
    heatmaps (`np.ndarray` of shape `(batch_size, num_keypoints, height, width)`):
        Model predicted heatmaps.

Returns:
    tuple: A tuple containing aggregated results.

    - coords (`np.ndarray` of shape `(batch_size, num_keypoints, 2)`):
        Predicted keypoint location.
    - scores (`np.ndarray` of shape `(batch_size, num_keypoints, 1)`):
        Scores (confidence) of the keypoints.
zHeatmaps should be np.ndarrayz Heatmaps should be 4-dimensionalg        ri   )rV   rV   r   )ºNNNr|   rT   )r|   r|   rV   )Ú
isinstancer9   r:   Ú	TypeErrorÚndimÚ
ValueErrorrk   ÚreshapeÚargmaxÚamaxÚtileÚastyperC   Úwhere)	ry   Ú
batch_sizeÚnum_keypointsÚ_rF   Úheatmaps_reshapedÚidxÚscoresÚpredss	   &        r$   Úget_keypoint_predictionsrŽ   ¯   s  € ô �h¤§
¡
×+Ò+ÜÐ7Ó8Ð8Ø‡}�}˜ÔÜÐ;Ó<Ð<à*2¯.©.Ñ'€J˜qØ ×(Ñ(¨*ÀRÐ)HÓIÐÜ
�)Š)Ð% qÓ
)×
1Ñ
1°:ÈaÐ2PÓ
Q€CÜ�WŠWÐ&¨Ó*×2Ñ2°JÈqÐ3QÓR€Fä�GŠG�C˜Ó#×*Ñ*¬2¯:©:Ó6€EØ˜7•^ eÕ+€Eˆ'�NØ˜7•^ uÕ,€Eˆ'�Nä�HŠH”R—W’W˜V YÓ/°#Ñ5°u¸bÓA€EØˆ=Ðr'   c                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\        R\         P                  /# )r   ÚcoordsÚbatch_heatmapsÚkernelrz   ©r9   r:   r;   )r"   s   "r$   r%   r%   Ð   s8   € ÷ 9ñ 9¬r¯z©zð 9Ì2Ï:É:ð 9Ô_bð 9Ôkm×kuÑkuñ 9r'   c                ó>  € VP                   w  r4rVV P                   ^ ,          pV^8X  g   W78X  g   \        R4      h\        V^,
          ^,          4      p\        P                  ! V U	U
u. uF#  p	V	 U
u. uF  p
\        V
RWˆ3R
R7      NK  	  up
NK%  	  up
p	4      p\        P                  ! VR^24      p\        P                  ! V4      p\        P                  ! VRRR7      P                  4       pV R,          ^,           V R,          ^,           V^,           ,          ,           pWÆ^,           V^,           ,          \        P                  ! ^ W4,          4      P                  RV4      ,          ,          pVP                  \        4      P                  R^4      pW¼,          pW¼^,           ,          pW¼V,           ^,           ,          pW¼V,           ^,           ,          pW¼V,
          ^,
          ,          pW¼^,
          ,          pW¼^,
          V,
          ,          pRVV,
          ,          pRVV,
          ,          p\        P                  ! VV.^R7      pVP                  Wt^^4      pV^V,          ,
          V,           pV^V,          ,
          V,           pRVV,
          V,
          V,           V,           V,
          V,
          V,           ,          p\        P                  ! VVVV.^R7      pVP                  Wt^^4      p\        P                  P                  V\        P                   ! \        P"                  4      P$                  \        P&                  ! ^4      ,          ,           4      pV \        P(                  ! R	VV4      P+                  4       ,          p V # u up
i u up
p	i )aÐ  DARK post-processing. Implemented by unbiased_data_processing.

Paper references:
- Huang et al. The Devil is in the Details: Delving into Unbiased Data Processing for Human Pose Estimation (CVPR 2020).
- Zhang et al. Distribution-Aware Coordinate Representation for Human Pose Estimation (CVPR 2020).

Args:
    coords (`np.ndarray` of shape `(num_persons, num_keypoints, 2)`):
        Initial coordinates of human pose.
    batch_heatmaps (`np.ndarray` of shape `(batch_size, num_keypoints, height, width)`):
        Batched heatmaps as predicted by the model.
        A batch_size of 1 is used for the bottom up paradigm where all persons share the same heatmap.
        A batch_size of `num_persons` is used for the top down paradigm where each person has its own heatmaps.
    kernel (`int`, *optional*, defaults to 3):
        Gaussian kernel size (K) for modulation.

Returns:
    `np.ndarray` of shape `(num_persons, num_keypoints, 2)` ):
        Refined coordinates.
zQThe batch size of heatmaps should be 1 or equal to the batch size of coordinates.gš™™™™™é?)ÚsigmaÚradiusÚaxesgü©ñÒMbP?Úedge)Úmoder>   rg   zijmn,ijnk->ijmkrU   )rS   rS   rY   rY   ).rT   ).rV   ri   )rk   r€   r;   r9   rB   r   ÚclipÚlogÚpadÚflattenÚaranger�   r…   ÚconcatenateÚlinalgr   ÚfinforC   ÚepsÚeyeÚeinsumÚsqueeze)r�   r‘   r’   r‡   rˆ   rG   rF   Ú
num_coordsr–   ry   ÚheatmapÚbatch_heatmaps_padÚindexÚi_Úix1Úiy1Úix1y1Úix1_y1_Úix1_Úiy1_ÚdxÚdyÚ
derivativeÚdxxÚdyyÚdxyÚhessians   &&&                        r$   Ú"post_dark_unbiased_data_processingr¸   Ð   sÛ  € ð* 0>×/CÑ/CÑ,€J˜vØ—‘˜a•€JØ˜!ŒO˜zÔ7ÜÐlÓmÐmÜ�&˜1•* Õ"Ó#€FÜ—X’Xñ +ô	
á*�ñ goÓoÑfnÐ[bŒ_˜W¨C¸Ð8HÈv×VÑfnÔoÙ*ò	
ó€Nô —W’W˜^¨U°BÓ7€NÜ—V’V˜NÓ+€NäŸš Ð0PÐW]Ô^×fÑfÓhÐØ�6�N˜QÕ &¨¥.°1Õ"4¸À½Õ!CÕC€EØ	�a�i˜F Q�JÕ'¬"¯)ª)°A°zÕ7QÓ*R×*ZÑ*ZÐ[]Ð_lÓ*mÕmÕm€EØ�L‰LœÓ×%Ñ% b¨!Ó,€EØ	Õ	"€BØ
 Q�YÕ
'€CØ
 U�]¨QÕ.Õ
/€CØ u�}¨qÕ0Õ1€EØ ¨¥°Õ!2Õ3€GØ a�iÕ(€DØ a�i¨%Õ/Õ0€DØ	��d•
Õ	€BØ	��d•
Õ	€BÜ—’  R ¨qÔ1€JØ×#Ñ# J¸qÀ!ÓD€JØ
��B•�,˜Õ
€CØ
��B•�,˜Õ
€CØ
�˜•˜sÕ" RÕ'¨"Õ,¨tÕ3°dÕ:¸WÕDÕ
E€CÜ�nŠn˜c 3¨¨SÐ1¸Ô:€GØ�o‰o˜j¸¸AÓ>€GÜ�i‰i�m‰m˜G¤b§h¢h¬r¯z©zÓ&:×&>Ñ&>ÄÇÂÈÃÕ&JÕJÓK€GØ
Œb�iŠiÐ)¨7°JÓ?×GÑGÓIÕI€FØ€Mùò; pùó	
s   Á)	N
Á2NÂN
ÎN
c          
      ó¸   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\         P                  /# )r   r�   rI   rJ   Úoutput_sizerz   ©r9   r:   )r"   s   "r$   r%   r%     sI   € ÷ -ñ -œBŸJ™Jð -´·
±
ð -Ä2Ç:Á:ð -Ô\^×\fÑ\fð -Ôkm×kuÑkuñ -r'   c                ó|  € V P                   ^,          R9  d   \        R4      h\        V4      ^8w  d   \        R4      h\        V4      ^8w  d   \        R4      h\        V4      ^8w  d   \        R4      hVR,          pV^,          V^ ,          R,
          ,          pV^ ,          V^,          R,
          ,          p\        P                  ! V 4      pV R	,          V,          V^ ,          ,           V^ ,          R,          ,
          VR	&   V R
,          V,          V^,          ,           V^,          R,          ,
          VR
&   V# )a'  Get final keypoint predictions from heatmaps and apply scaling and
translation to map them back to the image.

Note:
    num_keypoints: K

Args:
    coords (`np.ndarray` of shape `(num_keypoints, ndims)`):

        * If ndims=2, corrds are predicted keypoint location.
        * If ndims=4, corrds are composed of (x, y, scores, tags)
        * If ndims=5, corrds are composed of (x, y, scores, tags,
          flipped_tags)

    center (`np.ndarray` of shape `(2,)`):
        Center of the bounding box (x, y).
    scale (`np.ndarray` of shape `(2,)`):
        Scale of the bounding box wrt original image of width and height.
    output_size (`np.ndarray` of shape `(2,)`):
        Size of the destination heatmaps in (height, width) format.

Returns:
    np.ndarray: Predicted coordinates in the images.
z5Coordinates need to have either 2, 4 or 5 dimensions.z9Center needs to have 2 elements, one for x and one for y.z,Scale needs to consist of a width and heightz2Output size needs to consist of a height and widthç      i@rA   r>   )r   r=   é   ©r|   rT   ©r|   rV   )rk   r€   Úlenr9   Ú	ones_like)r�   rI   rJ   rº   rb   ra   Útarget_coordss   &&&&   r$   Útransform_predsrÄ     s	  € ð2 ‡|�|�A…˜iÔ'ÜÐPÓQÐQÜ
ˆ6ƒ{�aÔÜÐTÓUÐUÜ
ˆ5ƒz�Q„ÜÐGÓHÐHÜ
ˆ;Ó˜1ÔÜÐMÓNÐNð �E�M€Eð �A�h˜+ a�.¨3Õ.Õ/€GØ�A�h˜+ a�.¨3Õ.Õ/€Gä—L’L Ó(€MØ  �,¨Õ0°6¸!µ9Õ<¸uÀQ½xÈ#½~ÕM€M�$ÑØ  �,¨Õ0°6¸!µ9Õ<¸uÀQ½xÈ#½~ÕM€M�$ÑàÐr'   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   Úbboxesrz   r»   )r"   s   "r$   r%   r%   <  s"   € ÷ ñ œrŸz™zð ¬b¯j©jñ r'   c                óŠ   € V R,          V R,          ,           ^,
          V R&   V R,          V R,          ,           ^,
          V R&   V # )a�  
Converts bounding boxes from the COCO format to the Pascal VOC format.

In other words, converts from (top_left_x, top_left_y, width, height) format
to (top_left_x, top_left_y, bottom_right_x, bottom_right_y).

Args:
    bboxes (`np.ndarray` of shape `(batch_size, 4)):
        Bounding boxes in COCO format.

Returns:
    `np.ndarray` of shape `(batch_size, 4) in Pascal VOC format.
)r|   r   r¿   )r|   rR   rÀ   r(   )rÆ   s   &r$   Úcoco_to_pascal_vocrÈ   <  s?   € ð ˜$•< &¨¥,Õ.°Õ2€Fˆ4�LØ˜$•< &¨¥,Õ.°Õ2€Fˆ4�Là€Mr'   c                   ó.  a a€ ] tR tRt oRt]tR.t]t	]
tRRR^À/tRtRtRtRtV3R	 lV 3R
 llt]V3R lV 3R ll4       tRV3R lR llt]P,                  P.                  V3R lR l4       tRV3R lR lltRV3R lR lltRV3R lR lltRtVtV ;t# )ÚVitPoseImageProcessoriP  z6Torchvision backend for VitPose with affine transform.Úpixel_valuesrG   é   rF   Tr½   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# )r   Úkwargs)r   r   )r"   r#   s   "€r$   r%   Ú"VitPoseImageProcessor.__annotate___  s   ø€ ÷ #ñ #¡Ñ(CÕ!Dñ #r'   c                ó(   <€ \         SV `  ! R/ VB  R # )Nr(   )ÚsuperÚ__init__)ÚselfrÎ   Ú	__class__s   &,€r$   rÒ   ÚVitPoseImageProcessor.__init___  s   ø€ Ü‰ÒÑ"˜6Ô"r'   c                ó–   <€ V ^8„  d   QhRS[ RS[S[S[S[,          ,          ,          S[P                  ,          RS[S[,          RS[/# )r   ÚimagesÚboxesrÎ   rz   )r   r8   r!   r9   r:   r   r   r   )r"   r#   s   "€r$   r%   rÏ   c  sP   ø€ ÷ ;ñ ;áð;ñ ‘D™™e�Õ%Õ&©¯©Õ3ð;ñ Ñ4Õ5ð	;ñ
 
ñ;r'   c                ó&   <€ \         SV `  ! W3/ VB # )zô
boxes (`list[list[list[float]]]` or `np.ndarray`):
    List or array of bounding boxes for each image. Each box should be a list of 4 floats representing the
    bounding box coordinates in COCO format (top_left_x, top_left_y, width, height).
)rÑ   Ú
preprocess)rÓ   r×   rØ   rÎ   rÔ   s   &&&,€r$   rÚ   Ú VitPoseImageProcessor.preprocessb  s   ø€ ô ‰wÒ! &Ñ:°6Ñ:Ð:r'   c                óÂ   <€ V ^8„  d   QhRS[ RS[S[S[S[,          ,          ,          S[P                  ,          R,          RS[RS[RS[S[R3,          R,          RS[	/# )	r   r×   rØ   NÚdo_convert_rgbÚinput_data_formatÚdeviceztorch.devicerz   )
r   r8   r!   r9   r:   r    r   r   Ústrr   )r"   r#   s   "€r$   r%   rÏ   p  sr   ø€ ÷ 2ñ 2áð2ñ ‘D™™e�Õ%Õ&©¯©Õ3°dÕ:ð2ñ ð	2ñ
 ,ð2ñ ‘c˜>Ð)Õ*¨TÕ1ð2ñ 
ñ2r'   c                óV   € V P                  WWER7      pW&R&   V P                  ! V3/ VB # )z"Handle extra inputs beyond images.)r×   rÝ   rÞ   rß   rØ   )Ú_prepare_image_like_inputsÚ_preprocess)rÓ   r×   rØ   rÝ   rÞ   rß   rÎ   s   &&&&&&,r$   Ú_preprocess_image_like_inputsÚ3VitPoseImageProcessor._preprocess_image_like_inputsp  s>   € ð ×0Ñ0ØÐL]ð 1ó 
ˆð  ˆw‰Ø×Ò Ñ1¨&Ñ1Ð1r'   c                óZ   <€ V ^8„  d   QhRRRS[ S[,          RS[ S[,          RS[RS[RR/# )r   Úimageútorch.TensorrI   rJ   Úrotationrp   rz   )r7   r!   r   )r"   r#   s   "€r$   r%   rÏ   ‚  sO   ø€ ÷ ñ àðñ ‘e•ðñ ‘U�|ð	ñ
 ðñ ðð 
ñr'   c                óÂ  € \        WBR,          \        P                  ! VP                  VP                  34      R,
          VR,          4      pVP                  ^^^ 4      P                  4       P                  4       p\        WvVP                  VP                  3R7      p\        P                  ! V4      P                  ^^ ^4      P                  VP                  4      p	V	# )z7Apply an affine transformation to a torch tensor image.g       @rA   r½   )rn   ro   rp   )rc   r9   rB   rF   rG   ÚpermuteÚcpuÚnumpyrw   ÚtorchÚ
from_numpyÚtorß   )
rÓ   rç   rI   rJ   ré   rp   ÚtransformationÚimage_npÚtransformed_npÚtransformeds
   &&&&&&    r$   r   Ú&VitPoseImageProcessor.affine_transform�  s²   € ô )Ø˜s•l¤B§H¢H¨d¯j©j¸$¿+¹+Ð-FÓ$GÈ#Õ$MÈuÐW\Í}ó
ˆð —=‘=  A qÓ)×-Ñ-Ó/×5Ñ5Ó7ˆÜ*¨xÐQU×Q\ÑQ\Ð^b×^hÑ^hÐPiÔjˆÜ×&Ò& ~Ó6×>Ñ>¸qÀ!ÀQÓG×JÑJÈ5Ï<É<ÓXˆØÐr'   c          &      ón  <€ V ^8„  d   QhRS[ R,          RS[RS[RRRS[RS[R	S[R
S[RS[RS[S[ S[,          ,          R,          RS[S[ S[,          ,          R,          RS[R,          RS[R,          RS[R,          RS[S[,          R,          RS[RS[RS[ S[P                  ,          R,          RS[/# )r   r×   rè   Ú	do_resizerp   Úresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanNÚ	image_stdÚdo_padÚpad_sizeÚdisable_groupingÚreturn_tensorsr   r   rØ   rz   )	r8   r    r   r!   rà   r   r9   r:   r   )r"   r#   s   "€r$   r%   rÏ   “  s$  ø€ ÷ -añ -aá�^Õ$ð-añ ð-añ ð	-að
 Lð-añ ð-añ ð-añ ð-añ ð-añ ð-añ ™D¡�KÕ'¨$Õ.ð-añ ™4¡�;Õ&¨Õ-ð-añ �t•ð-añ ˜T•/ð-añ  �+ð-añ  ™jÕ(¨4Õ/ð!-añ" "ð#-añ$  ð%-añ& ‘b—j‘jÕ  4Õ'ð'-añ* 
ñ+-ar'   c           
     ó¸  € Vey   V'       dq   . p\        VV4       F\  w  ppV FP  p\        VVP                  VP                  VR7      w  ppV P	                  VVV^ VR7      pVP                  V4       KR  	  K^  	  Tp\        WR7      w  pp/ pVP                  4        F  w  ppV P                  VWxWšV4      pVVV&   K!  	  \        VV4      p \        RV /VR7      # )z!Custom preprocessing for VitPose.)r4   r5   r   )ré   rp   )r  rË   )ÚdataÚtensor_type)ÚziprK   rF   rG   r   Úappendr   ÚitemsÚrescale_and_normalizer   r   )!rÓ   r×   r÷   rp   rø   rù   rú   rû   rü   rý   rþ   rÿ   r   r  r  r  r   r   rØ   rÎ   Útransformed_imagesrç   Úimage_boxesr3   rI   rJ   Útransformed_imageÚgrouped_imagesÚgrouped_images_indexÚprocessed_images_groupedrk   Ústacked_imagesÚprocessed_imagess!   &&&&&&&&&&&&&&&&&&&,             r$   rã   Ú!VitPoseImageProcessor._preprocess“  s  € ð. Ò×!4Ø!#ÐÜ&)¨&°%Ö&8Ñ"��{Û&�CÜ$;ØØ$(§J¡JØ%)§[¡[Ø)9ô	%‘M�F˜Eð )-×(=Ñ(=¸eÀVÈUÐ]^ÐeiÐ(=Ó(jÐ%Ø&×-Ñ-Ð.?Ö@ó 'ñ '9ð (ˆFä/DÀVÔ/oÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>Ø!×7Ñ7Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ	 &<ô
 *Ð*BÐDXÓYÐÜ .Ð2BÐ!CÐQ_Ô`Ð`r'   c                ón   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[/# )r   ry   rI   rJ   r’   r“   )r"   r#   s   "€r$   r%   rÏ   Â  s?   ø€ ÷ ñ á—*‘*ðñ —
‘
ðñ �z‰zð	ñ
 ñr'   c                óÆ   € VP                   w  rVrx\        V4      w  rš\        W‘VR7      p\        V4       F'  p\	        W¼,          W,,          W<,          Wx.R7      W¼&   K)  	  Wº3# )zRGet final keypoint predictions from heatmaps and transform them back to the image.©r’   )rI   rJ   rº   )rk   rŽ   r¸   rj   rÄ   )rÓ   ry   rI   rJ   r’   r‡   r‰   rG   rF   r�   rŒ   r�   rq   s   &&&&&        r$   Úkeypoints_from_heatmapsÚ-VitPoseImageProcessor.keypoints_from_heatmapsÂ  s]   € ð (0§~¡~Ñ$ˆ
�vÜ1°(Ó;‰ˆÜ2°6ÈFÔSˆÜ�zÖ"ˆAÜ& u¥x¸½	ÈÍÐ`fÐ_nÔoˆE‹Hñ #àˆ}Ðr'   c                óÆ   <€ V ^8„  d   QhRRRS[ S[ S[ S[,          ,          ,          S[P                  ,          RS[RS[R,          RS[S[ S[,          ,          R,          /# )r   Úoutputsr   rØ   Úkernel_sizeÚ	thresholdNÚtarget_sizes)r8   r!   r9   r:   r;   r   r7   )r"   r#   s   "€r$   r%   rÏ   Ñ  sm   ø€ ÷ Fñ Fà)ðFñ ‘D™™e�Õ%Õ&©¯©Õ3ðFñ ð	Fñ
 ˜4•<ðFñ !¡4©¥;Õ.°Õ5ñFr'   c           
     óš  € \        V R4       VP                  P                  w  rg pVe   V\        V4      8w  d   \	        R4      h\
        P                  ! V^3\
        P                  R7      p	\
        P                  ! V^3\
        P                  R7      p
\        \        P                  ! V!  4      p\        V4       F–  pVeG   W\,          ^ ,          W\,          ^,          rí\
        P                  ! WÞWÞ.4      pW¼,          V,          W¼&   V P                  R,          V P                  R,          pp\        W¼,          VVR7      w  ppVWœR3&   VW¬R3&   K˜  	  V P                  VP                  P!                  4       P#                  4       WšVR7      w  pp\
        P                  ! V^3\
        P                  R7      pV	R,          VR&   V
R,          VR&   \$        P&                  ! V4      p\$        P&                  ! V4      p\$        P(                  ! ^ V4      p\$        P&                  ! \+        V4      4      p. p\-        VVV4      pV F  p. pV Fc  p\/        V4      w  ppp VP1                  4       pTp!Ve!   VV8„  p"VV",          pVV",          pV!V",          p!R	VR
VRV!RV /p#VP3                  V#4       Ke  	  VP3                  V4       K�  	  V# )a^  
Transform the heatmaps into keypoint predictions and transform them back to the image.

Args:
    outputs (`VitPoseEstimatorOutput`):
        VitPoseForPoseEstimation model outputs.
    boxes (`list[list[list[float]]]` or `np.ndarray`):
        List or array of bounding boxes for each image. Each box should be a list of 4 floats representing the bounding
        box coordinates in COCO format (top_left_x, top_left_y, width, height).
    kernel_size (`int`, *optional*, defaults to 11):
        Gaussian kernel size (K) for modulation.
    threshold (`float`, *optional*, defaults to None):
        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 be resize with the default value.
Returns:
    `list[list[Dict]]`: A list of dictionaries, each dictionary containing the keypoints and boxes for an image
    in the batch as predicted by the model.
rî   zTMake sure that you pass in as many target sizes as the batch dimension of the logitsr?   rF   rG   )r4   r5   r|   r  Ú	keypointsrŒ   ÚlabelsÚbbox)r|   :rT   r   N)r|   :r   r=   N)r   ry   rk   rÁ   r€   r9   r\   rC   r8   Ú	itertoolsÚchainrj   rB   rp   rK   r  rì   rí   rî   Útensorrž   rÈ   r  Únextr¥   r  )$rÓ   r  rØ   r  r  r  r‡   rˆ   r‰   ÚcentersÚscalesÚflattened_boxesrq   r4   r5   Úscale_factorrF   rG   rI   rJ   r�   rŒ   Ú	all_boxesÚposesr   Úbboxes_xyxyÚresultsÚpose_bbox_pairsÚimage_bboxesÚimage_resultsÚposeÚscoreÚ	bbox_xyxyÚkeypoints_labelsÚkeepÚpose_results$   &&&&&&                              r$   Úpost_process_pose_estimationÚ2VitPoseImageProcessor.post_process_pose_estimationÑ  s„  € ô8 	˜$ Ô(Ø*1×*:Ñ*:×*@Ñ*@Ñ'ˆ
 1 aØÒ#¨
´c¸,Ó6GÔ(GÜÐsÓtÐtÜ—(’(˜J¨˜?´"·*±*Ô=ˆÜ—’˜: q˜/´·±Ô<ˆÜœyŸš°Ñ6Ó7ˆÜ�zÖ"ˆAØÒ'Ø,8­O¸AÕ,>ÀÅÐPQÕ@R˜\Ü!Ÿxšx¨ÀKÐ(^Ó_�Ø%4Õ%7¸,Õ%F�Ñ"Ø ŸI™I gÕ.°·	±	¸(Õ0C�6ˆEÜ3°OÕ4FÐTYÐhnÔo‰MˆF�EØ"ˆG�q�D‰MØ ˆF�a�4‹Lñ #ð ×4Ñ4Ø×Ñ× Ñ Ó"×(Ñ(Ó*¨GÀKð 5ó 
‰ˆˆvô —H’H˜j¨!˜_´B·J±JÔ?ˆ	Ø# F�Oˆ	�&ÑØ" 6�Nˆ	�&ÑÜ—’˜UÓ#ˆÜ—’˜fÓ%ˆÜ—’˜a Ó/ˆÜ—l’lÔ#5°iÓ#@ÓAˆØ79ˆÜ˜e V¨[Ó9ˆÛ!ˆLØ;=ˆMÛ!�Ü)-¨oÓ)>Ñ&��e˜YØŸ™›�Ø#)Ð ØÒ(Ø  9Ñ,�DØ �:�DØ! $�K�EØ'7¸Õ'=Ð$Ø*¨D°(¸EÀ8ÐM]Ð_eÐgpÐq�Ø×$Ñ$ [Ö1ñ "ð �N‰N˜=Ö)ñ "ð ˆr'   r(   )N)Tr½   N)é   )r9  NN)r)   r*   r+   r,   r-   r   Úvalid_kwargsÚmodel_input_namesr	   rþ   r
   rÿ   rp   rû   rý   r   r   rÒ   r   rÚ   rä   rî   ÚcompilerÚdisabler   rã   r  r7  r/   r0   Ú__classcell__)rÔ   r#   s   @@r$   rÊ   rÊ   P  s¸   ù‡ € á@à.€LØ'Ð(Ðà&€JØ$€IØ�c˜7 CÐ(€DØ€JØ€LØÐØÐ÷#ó #ð ÷;ò ;ó ð;÷2ò 2ð" ‡^�^×Ñ÷ó ð÷"-aò -a÷^ò ÷F÷ Fò Fr'   rÊ   )r½   g      ô?)rR   )7r-   r"  r]   Útypingr   r   rí   r9   rî   Útorchvision.transforms.v2r   ÚtvFÚimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   Úimage_utilsr	   r
   r   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r   r   Úscipy.linalgr   Úscipy.ndimager   r   Úmodeling_vitposer   Ú
get_loggerr)   Úloggerr   rK   rc   rw   rŽ   r¸   rÄ   rÈ   rÊ   Ú__all__r(   r'   r$   Ú<module>rN     sÅ   ðñ )ã Û ß 'ã Û Ý 7å ;Ý 2ß E÷÷ ÷ 5÷õ ñ ×ÒÝ ß?çÝ8à	×	Ò	˜HÓ	%€ô	# ,°eõ 	#÷)õX"òJõ4÷B9õx-õ`ð( ôFÐ.ó Fó ðFðR #Ð
#‚r'   