ó
    qyüiãV  ã                   ót  • S r SSKrSSKrSSKJrJr  SSK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Jr  SS	K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J r J!r!J"r"  \ " 5       (       a  SSK#J$r$  SSK%J&r&J'r'  \(       a  SSK(J)r)  \!RT                  " \+5      r, " S S\SS9r-  S/S\.\/-  \R`                  -  S\1S\1S\2S\24
S jjr3S\2S\R`                  S\R`                  S\R`                  4S jr4S r5S \R`                  S!\.\R`                  \R`                  4   4S" jr6S0S#\R`                  S$\R`                  S%\1S!\R`                  4S& jjr7S#\R`                  S'\R`                  S(\R`                  S)\R`                  S!\R`                  4
S* jr8S+\R`                  S!\R`                  4S, jr9\ " S- S.\5      5       r:S./r;g)1z"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                   ó:   • \ rS rSr% Sr\S-  \S'   \S-  \S'   Srg)ÚVitPoseImageProcessorKwargsé7   a5  
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.
NÚdo_affine_transformÚnormalize_factor© )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚboolÚ__annotations__ÚfloatÚ__static_attributes__r"   ó    Úq/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/models/vitpose/image_processing_vitpose.pyr   r   7   s   ‡ ñð  ™Ó$Ø˜d‘lÖ"r,   r   F)ÚtotalÚboxÚimage_widthÚimage_heightr!   Úpadding_factorc                 ó  • U SS u  pVpxX-  n	[         R                  " XWS-  -   XhS-  -   /[         R                  S9n
XyU-  :”  a	  US-  U	-  nOXyU-  :  a  X‰-  n[         R                  " Xs-  Xƒ-  /[         R                  S9nX´-  nX«4$ )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é   ç      à?©Údtypeç      ð?)ÚnpÚarrayÚfloat32)r/   r0   r1   r!   r2   Ú
top_left_xÚ
top_left_yÚwidthÚheightÚaspect_ratioÚcenterÚscales               r-   Úbox_to_center_and_scalerC   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,   ÚthetaÚ
size_inputÚsize_dstÚsize_targetc                 ó¾  • [         R                  " U 5      n [         R                  " S[         R                  S9nUS   US   -  nUS   US   -  n[        R
                  " U 5      U-  US'   [        R                  " U 5      * U-  US'   USUS   -  [        R
                  " U 5      -  SUS   -  [        R                  " U 5      -  -   SUS   -  -   -  US	'   [        R                  " U 5      U-  US
'   [        R
                  " U 5      U-  US'   USUS   -  [        R                  " U 5      -  SUS   -  [        R
                  " U 5      -  -
  SUS   -  -   -  US'   U$ )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   r6   r   r   ©r   r   ©r   r   g      à¿r5   ©r   rI   ©r   r   ©r   r   ©r   rI   )r9   Údeg2radÚzerosr;   ÚmathÚcosÚsin)rD   rE   rF   rG   ÚmatrixÚscale_xÚscale_ys          r-   Úget_warp_matrixrX   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           
      ó‚  • [        U R                  S   5       Vs/ s H	  o0SU4   PM     nn[        R                  " U/ SQ/5      n[	        U5      nUS   US   US   US   US   US	   4u  US'   US'   US'   US'   US	'   US'   U Vs/ s H  n[        XvUS
S9PM     nn[        R                  " USS9nU$ s  snf s  snf )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.
éÿÿÿÿ.)r   r   r   rN   rM   rK   rJ   rO   rL   r   )Úoutput_shapeÚorder©Úaxis)ÚrangeÚshaper9   Úvstackr   r   Ústack)	ÚsrcÚMÚsizeÚiÚchannelsÚM_scipyÚM_invÚchannelÚnew_srcs	            r-   Úscipy_warp_affinerl   •   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   ›B7Â	B<ÚheatmapsÚreturnc                 ó¢  • [        U [        R                  5      (       d  [        S5      eU R                  S:w  a  [        S5      eU R                  u  pp4U R                  XS45      n[        R                  " US5      R                  XS45      n[        R                  " US5      R                  XS45      n[        R                  " US5      R                  [        R                  5      nUSS2SS2S	4   U-  USS2SS2S	4'   USS2SS2S4   U-  USS2SS2S4'   [        R                  " [        R                  " US5      S
:„  US5      nX‡4$ )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.ndarrayr4   z Heatmaps should be 4-dimensionalrZ   rI   r   )r   r   rI   Nr   g        )Ú
isinstancer9   ÚndarrayÚ	TypeErrorÚndimÚ
ValueErrorr`   ÚreshapeÚargmaxÚamaxÚtileÚastyper;   Úwhere)	rm   Ú
batch_sizeÚnum_keypointsÚ_r>   Ú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Øš1ša ˜7‘^ eÑ+€EŠ!ŠQ�ˆ'�NØš1ša ˜7‘^ uÑ,€EŠ!ŠQ�ˆ'�Nä�HŠH”R—W’W˜V YÓ/°#Ñ5°u¸bÓA€EØˆ=Ðr,   ÚcoordsÚbatch_heatmapsÚkernelc                 óv  • UR                   u  p4pVU R                   S   nUS:X  d  X7:X  d  [        S5      e[        US-
  S-  5      n[        R                  " U V	V
s/ s H!  n	U	 V
s/ s H  n
[        U
SXˆ4SS9PM     sn
PM#     sn
n	5      n[        R                  " USS	5      n[        R                  " U5      n[        R                  " US
SS9R                  5       nU S   S-   U S   S-   US-   -  -   nXÆS-   US-   -  [        R                  " SX4-  5      R                  SU5      -  -  nUR                  [        5      R                  SS5      nX¼   nX¼S-      nX¼U-   S-      nX¼U-   S-      nX¼U-
  S-
     nX¼S-
     nX¼S-
  U-
     nSUU-
  -  nSUU-
  -  n[        R                  " UU/SS9nUR                  XtSS5      nUSU-  -
  U-   nUSU-  -
  U-   nSUU-
  U-
  U-   U-   U-
  U-
  U-   -  n[        R                  " UUUU/SS9nUR                  XtSS5      n[        R                  R                  U[        R                   " [        R"                  5      R$                  [        R&                  " S5      -  -   5      nU [        R(                  " SUU5      R+                  5       -  n U $ s  sn
f s  sn
n	f )aÏ  DARK post-pocessing. 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.
r   r   zQThe batch size of heatmaps should be 1 or equal to the batch size of coordinates.rI   gš™™™™™é?rK   )ÚsigmaÚradiusÚaxesgü©ñÒMbP?é2   )rJ   rJ   rN   rN   Úedge)Úmode).r   ).r   rZ   r   r5   r]   zijmn,ijnk->ijmk)r`   rt   Úintr9   r:   r   ÚclipÚlogÚpadÚflattenÚarangeru   ry   ÚconcatenateÚlinalgr   Úfinfor;   ÚepsÚeyeÚeinsumÚsqueeze)rƒ   r„   r…   r{   r|   r?   r>   Ú
num_coordsrˆ   rm   Ú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   Á
J5
Á%J0Á<J5
Ê0J5
rA   rB   Úoutput_sizec                 óÔ  • U R                   S   S;  a  [        S5      e[        U5      S:w  a  [        S5      e[        U5      S:w  a  [        S5      e[        U5      S:w  a  [        S5      eUS-  nUS   US	   S
-
  -  nUS	   US   S
-
  -  n[        R                  " U 5      nU SS2S	4   U-  US	   -   US	   S-  -
  USS2S	4'   U SS2S4   U-  US   -   US   S-  -
  USS2S4'   U$ )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.
r   )rI   r4   é   z5Coordinates need to have either 2, 4 or 5 dimensions.rI   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@r   r8   Nr5   )r`   rt   Úlenr9   Ú	ones_like)rƒ   rA   rB   r­   rW   rV   Ú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Ø ¢ A ™,¨Ñ0°6¸!±9Ñ<¸uÀQ¹xÈ#¹~ÑM€M’!�Q�$ÑØ ¢ A ™,¨Ñ0°6¸!±9Ñ<¸uÀQ¹xÈ#¹~ÑM€M’!�Q�$ÑàÐr,   Úbboxesc                 óz   • U SS2S4   U SS2S4   -   S-
  U SS2S4'   U SS2S4   U SS2S4   -   S-
  U SS2S4'   U $ )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.
NrI   r   r   r   r"   )rµ   s    r-   Úcoco_to_pascal_vocr·   <  sW   € ð š!˜Q˜$‘< &ª¨A¨¡,Ñ.°Ñ2€FŠ1ˆaˆ4�LØš!˜Q˜$‘< &ª¨A¨¡,Ñ.°Ñ2€FŠ1ˆaˆ4�Là€Mr,   c            '       ó  ^ • \ rS rSrSr\rS/r\r	\
rSSS.rSrSrSrSrS	\\   4U 4S
 jjr\S\S\\\\         \R0                  -  S	\\   S\4U 4S jj5       r S7S\S\\\\         \R0                  -  S-  S\S\S\\S4   S-  S\4S jjr\ RB                  RD                  SSS\#\   S\#\   S\S\$SS4S j5       r%   S8S\S   S\S\$SSS\S \$S!\S"\S#\S$\\\   -  S-  S%\\\   -  S-  S&\S-  S'\$S-  S(\S-  S)\\&-  S-  S*\S+\S\\R0                  -  S-  S\4&S, jjr' S9S-\R0                  S\R0                  S\R0                  S.\(4S/ jjr)   S:S0S1S\\\\         \R0                  -  S2\(S3\S-  S4\&\\#   -  S-  4
S5 jjr*S6r+U =r,$ );ÚVitPoseImageProcessoriP  z6Torchvision backend for VitPose with affine transform.Úpixel_valuesé   éÀ   )r?   r>   Tr°   Úkwargsc                 ó&   >• [         TU ]  " S0 UD6  g )Nr"   )ÚsuperÚ__init__)Úselfr½   Ú	__class__s     €r-   rÀ   ÚVitPoseImageProcessor.__init___  s   ø€ Ü‰ÒÑ"˜6Ó"r,   ÚimagesÚboxesrn   c                 ó&   >• [         TU ]  " X40 UD6$ )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,   NÚdo_convert_rgbÚinput_data_formatÚdeviceztorch.devicec                 óP   • U R                  XXES9nX&S'   U R                  " U40 UD6$ )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,   Úimageztorch.TensorrA   rB   Úrotationre   c                 ó¤  • [        XBS-  [        R                  " UR                  UR                  45      S-
  US-  5      nUR                  SSS5      R                  5       R                  5       n[        XvUR                  UR                  4S9n[        R                  " U5      R                  SSS5      R                  UR                  5      n	U	$ )z7Apply an affine transformation to a torch tensor image.g       @r8   r°   r   rI   r   )rc   rd   re   )rX   r9   r:   r>   r?   ÚpermuteÚcpuÚnumpyrl   ÚtorchÚ
from_numpyÚtorË   )
rÁ   rÑ   rA   rB   rÒ   re   Ú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,   Ú	do_resizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdÚdo_padÚpad_sizeÚdisable_groupingÚreturn_tensorsr    r!   c           
      óœ  • Ubq  U(       aj  / n[        UU5       HV  u  nnU HJ  n[        UUR                  UR                  US9u  nnU R	                  UUUSUS9nUR                  U5        ML     MX     Un[        XS9u  nn0 nUR                  5        H  u  nnU R                  UXxXšU5      nUUU'   M!     [        UU5      n [        SU 0US9$ )z!Custom preprocessing for VitPose.)r0   r1   r!   r   )rÒ   re   )rê   rº   )ÚdataÚtensor_type)ÚziprC   r>   r?   r   Úappendr	   ÚitemsÚrescale_and_normalizer
   r   )!rÁ   rÄ   rß   re   rà   rá   râ   rã   rä   rå   ræ   rç   rè   ré   rê   rë   r    r!   rÅ   r½   Útransformed_imagesrÑ   Úimage_boxesr/   rA   rB   Útransformed_imageÚgrouped_imagesÚgrouped_images_indexÚprocessed_images_groupedr`   Ú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,   rm   r…   c                 ó¢   • UR                   u  pVpx[        U5      u  pš[        X‘US9n[        U5       H  n[	        X¼   X,   X<   Xx/S9X¼'   M     Xº4$ )zRGet final keypoint predictions from heatmaps and transform them back to the image.©r…   )rA   rB   r­   )r`   r‚   r¬   r_   r´   )rÁ   rm   rA   rB   r…   r{   r}   r?   r>   rƒ   r€   r�   rf   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,   Úoutputsr   Úkernel_sizeÚ	thresholdÚtarget_sizesc                 ó4  • [        U S5        UR                  R                  u  pg  nUb  U[        U5      :w  a  [	        S5      e[
        R                  " US4[
        R                  S9n	[
        R                  " US4[
        R                  S9n
[        [        R                  " U6 5      n[        U5       Hr  nUb.  X\   S   X\   S   pí[
        R                  " XÞXÞ/5      nX¼   U-  X¼'   U R                  S   U R                  S	   nn[        X¼   UUS
9u  nnUXœSS24'   UX¬SS24'   Mt     U R                  UR                  R!                  5       R#                  5       XšUS9u  nn[
        R                  " US4[
        R                  S9nU	SS2SS24   USS2SS24'   U
SS2SS24   USS2SS24'   [$        R&                  " U5      n[$        R&                  " U5      n[$        R(                  " SU5      n[$        R&                  " [+        U5      5      n/ n[-        UUU5      nU Ho  n/ nU HS  n[/        U5      u  nnn UR1                  5       nUn!Ub  UU:„  n"UU"   nUU"   nU!U"   n!UUU!U S.n#UR3                  U#5        MU     UR3                  U5        Mq     U$ )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×   NzTMake sure that you pass in as many target sizes as the batch dimension of the logitsrI   r6   r   r   r>   r?   )r0   r1   rý   r4   )Ú	keypointsr€   ÚlabelsÚbbox)r   rm   r`   r±   rt   r9   rQ   r;   ÚlistÚ	itertoolsÚchainr_   r:   re   rC   rþ   rÕ   rÖ   r×   Útensorr’   r·   rï   Únextr™   rð   )$rÁ   r   rÅ   r  r  r  r{   r|   r}   ÚcentersÚscalesÚflattened_boxesrf   r0   r1   Úscale_factorr>   r?   rA   rB   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Ñ?ˆ	Ø#¢A q¨ s F™Oˆ	’!�Q�q�S�&ÑØ"¢1 a¨ c 6™Nˆ	’!�Q�q�S�&ÑÜ—’˜UÓ#ˆÜ—’˜fÓ%ˆÜ—’˜a Ó/ˆÜ—l’lÔ#5°iÓ#@ÓAˆØ79ˆÜ˜e V¨[Ó9ˆÛ!ˆLØ;=ˆMÛ!�Ü)-¨oÓ)>Ñ&��e˜YØŸ™›�Ø#)Ð ØÑ(Ø  9Ñ,�DØ ™:�DØ! $™K�EØ'7¸Ñ'=Ð$Ø,0¸EÐM]ÐgpÑq�Ø×$Ñ$ [Ö1ñ "ð �N‰N˜=Ö)ñ "ð ˆr,   r"   )N)Tr°   N)é   )r   NN)-r#   r$   r%   r&   r'   r   Úvalid_kwargsÚmodel_input_namesr   ræ   r   rç   re   rã   rå   r    r!   r   rÀ   r   r   r  r*   r9   rq   r   rÇ   r(   r   r   ÚstrrÏ   r×   ÚcompilerÚdisableÚtupler   r   r   rÎ   r�   rþ   r  r+   Ú__classcell__)rÂ   s   @r-   r¹   r¹   P  sO  ø† á@à.€LØ'Ð(Ðà&€JØ$€IØ CÑ(€DØ€JØ€LØÐØÐð# Ð(CÑ!D÷ #ð ð;àð;ð �D˜˜e™Ñ%Ñ&¨¯©Ñ3ð;ð Ð4Ñ5ð	;ð
 
ö;ó ð;ð& 59ñ2àð2ð �D˜˜e™Ñ%Ñ&¨¯©Ñ3°dÑ:ð2ð ð	2ð
 ,ð2ð �c˜>Ð)Ñ*¨TÑ1ð2ð 
õ2ð" ‡^�^×Ñðàðð �e‘ðð �U‰|ð	ð
 ðð ðð 
óó ððD %)Ø"'Ø*.ñ'-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ðh ñà—*‘*ðð —
‘
ðð �z‰zð	ð
 õð& Ø"&Ø8<ñFà)ðFð �D˜˜e™Ñ%Ñ&¨¯©Ñ3ðFð ð	Fð
 ˜4‘<ðFð ! 4¨¡;Ñ.°Ñ5÷Fó Fr,   r¹   )r°   g      ô?)r   )<r'   r	  rR   Ú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   r&  r  rq   r�   r*   rC   rX   rl   r‚   r¬   r´   r·   r¹   Ú__all__r"   r,   r-   Ú<module>r7     sÖ  ðñ )ã Û ß 'ã Û Ý 7å ;Ý 2ß E÷÷ ÷ 5÷õ ñ ×ÑÝ ß?æÝ8à	×	Ò	˜HÓ	%€ô	# ,°eò 	#ð" $Ø ñ)Ø	�‰˜Ÿ
™
Ñ	"ð)àð)ð ð)ð ð	)ð
 õ)ðX"˜5ð "¨b¯j©jð "ÀBÇJÁJð "Ð]_×]gÑ]gô "òJð4 r§z¡zð °e¸B¿J¹JÈÏ
É
Ð<RÑ6Sô ñB9¨r¯z©zð 9È2Ï:É:ð 9Ð_bð 9Ðkm×kuÑkuõ 9ðx-˜BŸJ™Jð -°·
±
ð -À2Ç:Á:ð -Ð\^×\fÑ\fð -Ðkm×kuÑkuô -ð`˜rŸz™zð ¨b¯j©jô ð( ôFÐ.ó Fó ðFðR #Ð
#�r,   