o
    Vh                     @   sv   d dl Z d dlmZ d dlmZmZmZmZmZm	Z	 d dl
m  mZ ddlmZ G dd dejZG dd	 d	ZdS )
    N)Path)AnyCallableListOptionalTupleUnion   )_log_api_usage_oncec                   @   s   e Zd ZdZdZ				ddeeef dee	 dee	 dee	 ddf
d	d
Z
dedefddZdefddZdefddZde	dedee fddZdefddZdS )VisionDatasetaB  
    Base Class For making datasets which are compatible with torchvision.
    It is necessary to override the ``__getitem__`` and ``__len__`` method.

    Args:
        root (string, optional): Root directory of dataset. Only used for `__repr__`.
        transforms (callable, optional): A function/transforms that takes in
            an image and a label and returns the transformed versions of both.
        transform (callable, optional): A function/transform that takes in a PIL image
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        target_transform (callable, optional): A function/transform that takes in the
            target and transforms it.

    .. note::

        :attr:`transforms` and the combination of :attr:`transform` and :attr:`target_transform` are mutually exclusive.
       Nroot
transforms	transformtarget_transformreturnc                 C   sp   t |  t|trtj|}|| _|d u}|d up|d u}|r&|r&td|| _|| _	|r3t
||}|| _d S )NzGOnly transforms or transform/target_transform can be passed as argument)r
   
isinstancestrospath
expanduserr   
ValueErrorr   r   StandardTransformr   )selfr   r   r   r   has_transformshas_separate_transform r   O/var/www/vscode/kcb/lib/python3.10/site-packages/torchvision/datasets/vision.py__init__   s   


zVisionDataset.__init__indexc                 C      t )z
        Args:
            index (int): Index

        Returns:
            (Any): Sample and meta data, optionally transformed by the respective transforms.
        NotImplementedError)r   r   r   r   r   __getitem__8   s   zVisionDataset.__getitem__c                 C   r    Nr!   r   r   r   r   __len__B      zVisionDataset.__len__c                    s   d j j }d   g} jd ur|d j  |   7 }t dr6 jd ur6|t	 jg7 }|g fdd|D  }d
|S )NzDataset zNumber of datapoints: zRoot location: r   c                    s   g | ]	}d  j  | qS ) )_repr_indent.0liner%   r   r   
<listcomp>M   s    z*VisionDataset.__repr__.<locals>.<listcomp>
)	__class____name__r&   r   append
extra_repr
splitlineshasattrr   reprjoin)r   headbodylinesr   r%   r   __repr__E   s   

zVisionDataset.__repr__r7   c                    8   |   }  |d  g fdd|dd  D  S )Nr   c                        g | ]}d  dt  |qS z{}{}r(   formatlenr*   r7   r   r   r-   R        z8VisionDataset._format_transform_repr.<locals>.<listcomp>   r:   r3   r   r   r7   r9   r   rA   r   _format_transform_reprP      ,z$VisionDataset._format_transform_reprc                 C   s   dS )N r   r%   r   r   r   r2   T   r'   zVisionDataset.extra_repr)NNNN)r0   
__module____qualname____doc__r)   r   r   r   r   r   r   intr   r#   r&   r:   r   rF   r2   r   r   r   r   r   
   s.    


r   c                   @   sr   e Zd Zddee dee ddfddZdededeeef fd	d
Zdede	de
e	 fddZde	fddZdS )r   Nr   r   r   c                 C   s   || _ || _d S r$   r   r   )r   r   r   r   r   r   r   Y   s   
zStandardTransform.__init__inputtargetc                 C   s0   | j d ur
|  |}| jd ur| |}||fS r$   rM   )r   rN   rO   r   r   r   __call__]   s
   



zStandardTransform.__call__r7   c                    r;   )Nr   c                    r<   r=   r>   r*   rA   r   r   r-   f   rB   z<StandardTransform._format_transform_repr.<locals>.<listcomp>rC   rD   rE   r   rA   r   rF   d   rG   z(StandardTransform._format_transform_reprc                 C   sL   | j jg}| jd ur|| | jd7 }| jd ur!|| | jd7 }d|S )NzTransform: zTarget transform: r.   )r/   r0   r   rF   r   r6   )r   r8   r   r   r   r:   h   s   



zStandardTransform.__repr__)NN)r0   rI   rJ   r   r   r   r   r   rP   r   r   rF   r:   r   r   r   r   r   X   s
     r   )r   pathlibr   typingr   r   r   r   r   r   torch.utils.datautilsdatar
   Datasetr   r   r   r   r   r   <module>   s     N