
    Ph                        d dl mZ d dlmZ d dlmZmZmZ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 G d
 de      Zy)    )annotations)Enum)AnyMappingOptionalSequenceTupleUnionN)tree_flatten   )TVTensorc                      e Zd ZdZdZdZdZy)BoundingBoxFormatztCoordinate format of a bounding box.

    Available formats are

    * ``XYXY``
    * ``XYWH``
    * ``CXCYWH``
    XYXYXYWHCXCYWHN)__name__
__module____qualname____doc__r   r   r        qC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/tv_tensors/_bounding_boxes.pyr   r      s     DDFr   r   c                      e Zd ZU dZded<   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	)BoundingBoxesa  :class:`torch.Tensor` subclass for bounding boxes.

    .. note::
        There should be only one :class:`~torchvision.tv_tensors.BoundingBoxes`
        instance per sample e.g. ``{"img": img, "bbox": BoundingBoxes(...)}``,
        although one :class:`~torchvision.tv_tensors.BoundingBoxes` object can
        contain multiple bounding boxes.

    Args:
        data: Any data that can be turned into a tensor with :func:`torch.as_tensor`.
        format (BoundingBoxFormat, str): Format of the bounding box.
        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``.
    r   formatTuple[int, int]canvas_sizeT)
check_dimsc               (   |rI|j                   dk(  r|j                  d      }n(|j                   dk7  rt        d|j                    d      t        |t              rt
        |j                            }|j                  |       }||_        ||_	        |S )Nr   r      z Expected a 1D or 2D tensor, got D)
ndim	unsqueeze
ValueError
isinstancestrr   upperas_subclassr   r   )clstensorr   r   r   bounding_boxess         r   _wrapzBoundingBoxes._wrap3   s    {{a))!,! #CFKK=PQ!RSSfc"&v||~6F++C0 &%0"r   Ndtypedevicerequires_gradc               T    | j                  ||||      }| j                  |||      S )Nr.   r   r   )
_to_tensorr-   )r*   datar   r   r/   r0   r1   r+   s           r   __new__zBoundingBoxes.__new__A   s0     E&P]^yyKyHHr   c                   t        ||rt        |j                               ndz         \  }}t        d |D              }|j                  |j
                  ct        |t        j                        r+t        |t              st        j                  |d      }|S t        |t        t        f      r t        |      fd|D              }|S )Nr   c              3  B   K   | ]  }t        |t              s|  y w)N)r&   r   ).0xs     r   	<genexpr>z-BoundingBoxes._wrap_output.<locals>.<genexpr>[   s     #[{!jM>ZA{s   Fr   r   r   c              3  P   K   | ]  }t         j                  |d         yw)Fr<   N)r   r-   )r9   partr   r   s     r   r;   z-BoundingBoxes._wrap_output.<locals>.<genexpr>a   s,      "pvhl##D[]b#cpvs   #&)r   tuplevaluesnextr   r   r&   torchTensorr   r-   listtype)	r*   outputargskwargsflat_params_first_bbox_from_argsr   r   s	          @@r   _wrap_outputzBoundingBoxes._wrap_outputN   s     &deFMMO.DTV&WXQ##[{#[[299;O;[;[fell+Jv}4U"((Kdi(jF
 	 .!T&\ "pv" F r   )tensor_contentsc               P    | j                  | j                  | j                        S )Nr3   )
_make_reprr   r   )selfrM   s     r   __repr__zBoundingBoxes.__repr__f   s    dkkt?O?OPPr   )
r+   torch.Tensorr   Union[BoundingBoxFormat, str]r   r   r   boolreturnr   )r5   r   r   rS   r   r   r/   zOptional[torch.dtype]r0   z'Optional[Union[torch.device, str, int]]r1   zOptional[bool]rU   r   )r   N)rF   rR   rG   zSequence[Any]rH   zOptional[Mapping[str, Any]]rU   r   )rM   r   rU   r'   )
r   r   r   r   __annotations__classmethodr-   r6   rL   rQ   r   r   r   r   r      s    (    EI  & (,:>(,II .	I
 %I %I 8I &I 
I  !.2	  ,	
 
 . 26 Qr   r   )
__future__r   enumr   typingr   r   r   r   r	   r
   rB   torch.utils._pytreer   
_tv_tensorr   r   r   r   r   r   <module>r]      s6    "  A A  ,   LQH LQr   