U
    h                     @  sP   d dl mZ d dlmZmZmZ d dlZd dlZddl	m
Z
 G dd de
ZdS )    )annotations)AnyOptionalUnionN   )TVTensorc                   @  sF   e Zd ZdZddddddddd dd	d
ZdddddddZdS )Imagea  :class:`torch.Tensor` subclass for images with shape ``[..., C, H, W]``.

    .. note::

        In the :ref:`transforms <transforms>`, ``Image`` instances are largely
        interchangeable with pure :class:`torch.Tensor`. See
        :ref:`this note <passthrough_heuristic>` for more details.

    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. If omitted, will be inferred from
            ``data``.
        device (torch.device, optional): Desired device. If omitted and ``data`` is a
            :class:`torch.Tensor`, the device is taken from it. Otherwise, the image is constructed on the CPU.
        requires_grad (bool, optional): Whether autograd should record operations. If omitted and
            ``data`` is a :class:`torch.Tensor`, the value is taken from it. Otherwise, defaults to ``False``.
    Ndtypedevicerequires_gradr   zOptional[torch.dtype]z'Optional[Union[torch.device, str, int]]zOptional[bool])datar
   r   r   returnc                C  sd   t |tjjr$ddlm} ||}| j||||d}|jdk rFtn|jdkrZ|	d}|
| S )Nr   )
functionalr	      )
isinstancePILr   Ztorchvision.transforms.v2r   Zpil_to_tensorZ
_to_tensorndim
ValueErrorZ	unsqueezeZas_subclass)clsr   r
   r   r   FZtensor r   O/var/www/html/venv/lib/python3.8/site-packages/torchvision/tv_tensors/_image.py__new__   s    



zImage.__new__)tensor_contentsstr)r   r   c                C  s   |   S )N)Z
_make_repr)selfr   r   r   r   __repr__4   s    zImage.__repr__)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   )
__future__r   typingr   r   r   Z	PIL.Imager   ZtorchZ
_tv_tensorr   r   r   r   r   r   <module>   s
   