
    %`i                    b    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dS )	    )annotations)AnyMappingSequenceN)tree_flatten   )TVTensorc                  z    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	dS )'	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_dimstensortorch.Tensorr   boolreturnc                   |rI|j         dk    r|                    d          }n(|j        d         dk    rt          d|j                   |                    |           }||_        |S )Nr   r      z)Expected a tensor of shape (..., 2), not )ndim	unsqueezeshape
ValueErroras_subclassr   )clsr   r   r   pointss        u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchvision/tv_tensors/_keypoints.py_wrapzKeyPoints._wrap;   sx     	]{a))!,,b!Q&& ![V\![![\\\##C(((    Ndtypedevicerequires_graddatar   r!   torch.dtype | Noner"   torch.device | str | int | Noner#   bool | Nonec               b    |                      ||||          }|                     ||          S )Nr    r   )
_to_tensorr   )r   r$   r   r!   r"   r#   r   s          r   __new__zKeyPoints.__new__F   s4     E&P]^^yy[y999r    outputargsSequence[Any]kwargsMapping[str, Any] | Nonec                   t          ||r!t          |                                          ndz             \  }}t          d |D                       }|j        t          |t          j                  r3t          |t                    st          	                    |d          }n@t          |t          t          f          r$ t          |          fd|D                       }|S )Nr,   c              3  D   K   | ]}t          |t                    |V  d S )N)
isinstancer   ).0xs     r   	<genexpr>z)KeyPoints._wrap_output.<locals>.<genexpr>[   s2      (\(\q:aQZC[C[(\(\(\(\(\(\(\r   Fr   r   c              3  R   K   | ]!}t                               |d           V  "dS )Fr8   N)r   r   )r5   partr   s     r   r7   z)KeyPoints._wrap_output.<locals>.<genexpr>b   s7      !v!vgk)//$K\a/"b"b!v!v!v!v!v!vr   )r   tuplevaluesnextr   r4   torchTensorr   r   listtype)r   r-   r.   r0   flat_params_first_keypoints_from_argsr   s          @r   _wrap_outputzKeyPoints._wrap_outputR   s     &d.VeFMMOO.D.D.DTV&WXXQ$((\(\K(\(\(\$\$\!/;fel++ 	wJvy4Q4Q 	w__VQV_WWFF.. 	w!T&\\!v!v!v!vou!v!v!vvvFr   )tensor_contentsrF   strc               8    |                      | j                  S )Nr)   )
_make_reprr   )selfrF   s     r   __repr__zKeyPoints.__repr__e   s    4+;<<<r   )r   r   r   r   r   r   r   r   )r$   r   r   r   r!   r%   r"   r&   r#   r'   r   r   )r,   N)r-   r   r.   r/   r0   r1   r   r   )rF   r   r   rG   )
__name__
__module____qualname____doc____annotations__classmethodr   r+   rE   rK   r,   r   r   r   r      s         + +Z !   ]a      [ %)26%)
: 
: 
: 
: 
: 
:  !+/	    [$ 26 = = = = = = = =r   r   )
__future__r   typingr   r   r   r>   torch.utils._pytreer   
_tv_tensorr	   r   r,   r   r   <module>rV      s    " " " " " " ) ) ) ) ) ) ) ) ) )  , , , , , ,            [= [= [= [= [= [= [= [= [= [=r   