
    x h                    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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        }/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/torchvision/tv_tensors/_keypoints.py_wrapzKeyPoints._wrap;   sf    {{a))!,b!Q& #LV\\N![\\##C((    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__F   s.     E&P]^yy[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>[   s     (\q:aQZC[(\s   Fr   r   c              3  N   K   | ]  }t         j                  |d         yw)Fr-   N)r   r   )r*   partr   s     r   r,   z)KeyPoints._wrap_output.<locals>.<genexpr>b   s"     !vgk)//$K\a/"b!vs   "%)r   tuplevaluesnextr   r)   torchTensorr   r   listtype)r   outputargskwargsflat_params_first_keypoints_from_argsr   s          @r   _wrap_outputzKeyPoints._wrap_outputR   s     &deFMMO.DTV&WXQ$((\K(\$\!/;;fell+Jvy4Q__VQV_WF  .!T&\!vou!vvFr   )tensor_contentsc               :    | j                  | j                        S )Nr"   )
_make_reprr   )selfr>   s     r   __repr__zKeyPoints.__repr__e   s    4+;+;<<r   )r   torch.Tensorr   r   r   boolreturnr   )r$   r   r   r   r   ztorch.dtype | Noner   ztorch.device | str | int | Noner    zbool | NonerE   r   )r'   N)r7   rC   r8   zSequence[Any]r9   zMapping[str, Any] | NonerE   r   )r>   r   rE   str)
__name__
__module____qualname____doc____annotations__classmethodr   r%   r=   rB   r'   r   r   r   r      s    +Z ! ]a   %)26%)
:
: %	
:
 "
: 0
: #
: 

:  !+/	  )	
 
 $ 26 =r   r   )
__future__r   typingr   r   r   r3   torch.utils._pytreer   
_tv_tensorr	   r   r'   r   r   <module>rQ      s%    " ) )  ,  [= [=r   