a
    d                     @  sh   d dl mZ d dlmZmZmZmZmZ d dlZ	d dl
Z
d dlmZ ddlmZmZ G dd deZdS )	    )annotations)AnyListOptionalTupleUnionN)InterpolationMode   )_FillTypeJIT	Datapointc                
   @  s  e Zd ZdZedd dddZdddddd	d
dd dddZed dd dddZeddddZ	d dddZ
d dddZejddfddddd dd d!Zd"d"d"d"d d#d$d%Zdd d&d'd(Zejdfd"d"d"d"dddd d)d*d+ZdFdd-d.d d/d0d1Zejd2ddfd3dd4d5d6d d7d8d9Zejddfd:d;d3d;dd6d5d d<d=d>Zejddfd?d?dd6d5d d@dAdBZejdfddd6d dCdDdEZdS )GMaska>  [BETA] :class:`torch.Tensor` subclass for segmentation and detection masks.

    Args:
        data (tensor-like, PIL.Image.Image): Any data that can be turned into a tensor with :func:`torch.as_tensor` as
            well as PIL images.
        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``.
    ztorch.Tensor)tensorreturnc                 C  s
   | | S N)as_subclass)clsr    r   e/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torchvision/datapoints/_mask.py_wrap   s    z
Mask._wrapNdtypedevicerequires_gradr   zOptional[torch.dtype]z'Optional[Union[torch.device, str, int]]zOptional[bool])datar   r   r   r   c                C  s@   t |tjjr$ddlm} ||}| j||||d}| |S )Nr   )
functionalr   )
isinstancePILZImageZtorchvision.transforms.v2r   Zpil_to_tensorZ
_to_tensorr   )r   r   r   r   r   Fr   r   r   r   __new__   s
    
zMask.__new__)otherr   r   c                 C  s
   |  |S r   )r   )r   r   r   r   r   r   	wrap_like.   s    zMask.wrap_likezTuple[int, int])r   c                 C  s   t | jdd  S )N)tupleshape)selfr   r   r   spatial_size6   s    zMask.spatial_sizec                 C  s    | j | tj}t| |S r   )_FZhorizontal_flip_maskr   torchTensorr   r    r$   outputr   r   r   horizontal_flip:   s    zMask.horizontal_flipc                 C  s    | j | tj}t| |S r   )r&   Zvertical_flip_maskr   r'   r(   r   r    r)   r   r   r   vertical_flip>   s    zMask.vertical_flipwarnz	List[int]zUnion[InterpolationMode, int]zOptional[int]zOptional[Union[str, bool]])sizeinterpolationmax_size	antialiasr   c                 C  s&   | j j| tj||d}t| |S )N)r0   )r&   Zresize_maskr   r'   r(   r   r    )r$   r.   r/   r0   r1   r*   r   r   r   resizeB   s    zMask.resizeint)topleftheightwidthr   c                 C  s(   | j | tj||||}t| |S r   )r&   Z	crop_maskr   r'   r(   r   r    )r$   r4   r5   r6   r7   r*   r   r   r   cropL   s    z	Mask.crop)output_sizer   c                 C  s$   | j j| tj|d}t| |S )N)r9   )r&   Zcenter_crop_maskr   r'   r(   r   r    )r$   r9   r*   r   r   r   center_cropP   s    zMask.center_crop)r4   r5   r6   r7   r.   r/   r1   r   c           	      C  s,   | j j| tj|||||d}t| |S )N)r.   )r&   Zresized_crop_maskr   r'   r(   r   r    )	r$   r4   r5   r6   r7   r.   r/   r1   r*   r   r   r   resized_cropT   s    
 zMask.resized_cropconstantz(Optional[Union[int, float, List[float]]]str)paddingfillpadding_moder   c                 C  s(   | j j| tj|||d}t| |S )N)r@   r?   )r&   Zpad_maskr   r'   r(   r   r    )r$   r>   r?   r@   r*   r   r   r   pada   s    zMask.padFfloatboolzOptional[List[float]]r
   )angler/   expandcenterr?   r   c                 C  s*   | j j| tj||||d}t| |S )N)rE   rF   r?   )r&   Zrotate_maskr   r'   r(   r   r    )r$   rD   r/   rE   rF   r?   r*   r   r   r   rotatej   s    zMask.rotatezUnion[int, float]zList[float])rD   	translatescaleshearr/   r?   rF   r   c           	   	   C  s.   | j j| tj||||||d}t| |S )N)rH   rI   rJ   r?   rF   )r&   Zaffine_maskr   r'   r(   r   r    )	r$   rD   rH   rI   rJ   r/   r?   rF   r*   r   r   r   affineu   s    

	zMask.affinezOptional[List[List[int]]])startpoints	endpointsr/   r?   coefficientsr   c                 C  s*   | j j| tj||||d}t| |S )N)r?   rN   )r&   Zperspective_maskr   r'   r(   r   r    )r$   rL   rM   r/   r?   rN   r*   r   r   r   perspective   s    zMask.perspective)displacementr/   r?   r   c                 C  s&   | j j| tj||d}t| |S )N)r?   )r&   Zelastic_maskr   r'   r(   r   r    )r$   rP   r/   r?   r*   r   r   r   elastic   s    zMask.elastic)Nr<   )__name__
__module____qualname____doc__classmethodr   r   r    propertyr%   r+   r,   r   ZNEARESTr2   r8   r:   r;   rA   rG   rK   rO   rQ   r   r   r   r   r      sR   
  r   )
__future__r   typingr   r   r   r   r   Z	PIL.Imager   r'   Ztorchvision.transformsr   Z
_datapointr
   r   r   r   r   r   r   <module>   s   