Ë
    èÓ^jç  ã                  óZ   — d dl mZ d dlmZmZmZ d dlZd dlmZ ddl	m
Z
  G d„ de
«      Zy)	é    )Úannotations)ÚAnyÚMappingÚSequenceN)Útree_flattené   )ÚTVTensorc                  ó¢   — e Zd ZU dZded<   eddœdd„«       Zedd„«       Zdddd	œ	 	 	 	 	 	 	 	 	 	 	 dd
„Ze	 	 d	 	 	 	 	 	 	 dd„«       Z	ddœdd„Z
y)Ú	KeyPointsu!	  :class:`torch.Tensor` subclass for tensors with shape ``[..., 2]`` that represent points in an image.

    .. note::
        Support for keypoints was released in TorchVision 0.23 and is currently
        a BETA feature. We don't expect the API to change, but there may be some
        rare edge-cases. If you find any issues, please report them on our bug
        tracker: https://github.com/pytorch/vision/issues?q=is:open+is:issue
        Each point is represented by its X and Y coordinates along the width and
        height dimensions, respectively.

    Each point is represented by its X and Y coordinates along the width and height dimensions, respectively.

    KeyPoints may represent any object that can be represented by sequences of 2D points:

    - `Polygonal chains <https://en.wikipedia.org/wiki/Polygonal_chain>`_,
      including polylines, BÃ©zier curves, etc., which can be of shape
      ``[N_chains, N_points, 2]``.
    - Polygons, which can be of shape ``[N_polygons, N_points, 2]``.
    - Skeletons, which can be of shape ``[N_skeletons, N_bones, 2, 2]`` for
      pose-estimation models.

    .. note::
        Like for :class:`torchvision.tv_tensors.BoundingBoxes`, there should
        only be a single instance of the
        :class:`torchvision.tv_tensors.KeyPoints` class per sample e.g.
        ``{"img": img, "poins_of_interest": KeyPoints(...)}``, although one
        :class:`torchvision.tv_tensors.KeyPoints` object can contain multiple
        key points

    Args:
        data: Any data that can be turned into a tensor with
            :func:`torch.as_tensor`.
        canvas_size (two-tuple of ints): Height and width of the corresponding
            image or video.
        dtype (torch.dtype, optional): Desired data type of the bounding box. If
            omitted, will be inferred from ``data``.
        device (torch.device, optional): Desired device of the bounding box. If
            omitted and ``data`` is a :class:`torch.Tensor`, the device is taken
            from it. Otherwise, the bounding box is constructed on the CPU.
        requires_grad (bool, optional): Whether autograd should record
            operations on the bounding box. If omitted and ``data`` is a
            :class:`torch.Tensor`, the value is taken from it. Otherwise,
            defaults to ``False``.
    útuple[int, int]Úcanvas_sizeT)Ú
check_dimsc               óÐ   — |rK|j                   dk(  r|j                  d«      }n*|j                  d   dk7  rt        d|j                  › �«      ‚|j	                  | «      }||_        |S )Nr   r   éÿÿÿÿé   z)Expected a tensor of shape (..., 2), not )ÚndimÚ	unsqueezeÚshapeÚ
ValueErrorÚas_subclassr   )ÚclsÚtensorr   r   Úpointss        úl/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torchvision/tv_tensors/_keypoints.pyÚ_wrapzKeyPoints._wrap;   sf   € áØ�{‰{˜aÒØ×)Ñ)¨!Ó,‘Ø—‘˜bÑ! QÒ&Ü Ð#LÈVÏ\É\ÈNÐ![Ó\Ð\Ø×#Ñ# CÓ(ˆØ(ˆÔØˆó    c                ó\   — | j                  ||j                  d|j                  «      ¬«      S )Nr   ©r   )r   Úgetr   )r   r   ÚlikeÚkwargss       r   ÚwrapzKeyPoints.wrapF   s/   € à�y‰yØØŸ
™
 =°$×2BÑ2BÓCð ó 
ð 	
r   N©ÚdtypeÚdeviceÚrequires_gradc               óR   — | j                  ||||¬«      }| j                  ||¬«      S )Nr#   r   )Ú
_to_tensorr   )r   Údatar   r$   r%   r&   r   s          r   Ú__new__zKeyPoints.__new__M   s.   € ð —‘ ¨E¸&ÐP]�Ó^ˆØ�y‰y˜¨[ˆyÓ9Ð9r   c                ó„  ‡— t        ||rt        |j                  «       «      ndz   «      \  }}t        d„ |D «       «      }|j                  Št        |t        j                  «      r*t        |t        «      st        j                  |‰d¬«      }|S t        |t        t        f«      r t        |«      ˆfd„|D «       «      }|S )N© c              3  óB   K  — | ]  }t        |t        «      sŒ|–— Œ y ­w)N)Ú
isinstancer   )Ú.0Úxs     r   ú	<genexpr>z)KeyPoints._wrap_output.<locals>.<genexpr>b   s   è ø€ Ò(\¨qÄ:ÈaÔQZÕC[¬Ñ(\ùs   ‚˜F©r   r   c              3  óN   •K  — | ]  }t         j                  |‰d ¬«      –— Œ y­w)Fr2   N)r   r   )r/   Úpartr   s     €r   r1   z)KeyPoints._wrap_output.<locals>.<genexpr>i   s"   øè ø€ Ò!vÐgk¤)§/¡/°$ÀKÐ\a /×"bÑ!vùs   ƒ"%)r   ÚtupleÚvaluesÚnextr   r.   ÚtorchÚTensorr   r   ÚlistÚtype)r   ÚoutputÚargsr!   Úflat_paramsÚ_Úfirst_keypoints_from_argsr   s          @r   Ú_wrap_outputzKeyPoints._wrap_outputY   s£   ø€ ô & dÉ¬e°F·M±M³OÔ.DÐTVÑ&WÓX‰ˆ�QÜ$(Ñ(\°KÔ(\Ó$\Ð!Ø/×;Ñ;ˆä�fœeŸl™lÔ+´J¸vÄyÔ4QÜ—_‘_ V¸ÐQV�_ÓWˆFð ˆô ˜¤¬ Ô.à!”T˜&“\Ó!vÐouÔ!vÓvˆFØˆr   )Útensor_contentsc               ó:   — | j                  | j                  ¬«      S )Nr   )Ú
_make_reprr   )ÚselfrB   s     r   Ú__repr__zKeyPoints.__repr__l   s   € Ø�‰¨4×+;Ñ+;ˆÓ<Ð<r   )r   útorch.Tensorr   r   r   ÚboolÚreturnr   )r   rG   r    r   r!   r   rI   r   )r)   r   r   r   r$   ztorch.dtype | Noner%   ztorch.device | str | int | Noner&   zbool | NonerI   r   )r,   N)r<   rG   r=   zSequence[Any]r!   zMapping[str, Any] | NonerI   r   )rB   r   rI   Ústr)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__Úclassmethodr   r"   r*   rA   rF   r,   r   r   r   r      sÏ   … ñ+ðZ !Ó àØ]aô ó ðð ò
ó ð
ð %)Ø26Ø%)ñ
:àð
:ð %ð	
:ð
 "ð
:ð 0ð
:ð #ð
:ð 
ó
:ð ð !Ø+/ð	àðð ðð )ð	ð
 
òó ðð$ 26ö =r   r   )Ú
__future__r   Útypingr   r   r   r8   Útorch.utils._pytreer   Ú
_tv_tensorr	   r   r,   r   r   ú<module>rU      s%   ðÝ "ç )Ñ )ã Ý ,å  ôb=�õ b=r   