
    kh                         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c mZ ddlmZ  G d dej                        Z G d d	      Zy)
    N)Path)AnyCallableListOptionalTupleUnion   )_log_api_usage_oncec                       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	Z
d
edefdZdefdZdefdZde	dedee   fdZdefdZy)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                    t        |        t        |t              rt        j                  j                  |      }|| _        |d u}|d uxs |d u}|r|rt        d      || _        || _	        |rt        ||      }|| _        y )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_transforms          W/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/vision.py__init__zVisionDataset.__init__   s     	D!dC 77%%d+D	#4/!*$!6!V:JRV:V4fgg # 0!*96FGJ$    indexc                     t         )z
        Args:
            index (int): Index

        Returns:
            (Any): Sample and meta data, optionally transformed by the respective transforms.
        NotImplementedError)r   r"   s     r   __getitem__zVisionDataset.__getitem__8   s
     "!r!   c                     t         Nr$   r   s    r   __len__zVisionDataset.__len__B   s    !!r!   c                    d| j                   j                  z   }d| j                          g}| j                  |j	                  d| j                          || j                         j                         z  }t        | d      r%| j                  |t        | j                        gz  }|g|D cg c]  }d| j                  z  |z    c}z   }dj                  |      S c c}w )NzDataset zNumber of datapoints: zRoot location: r    
)	__class____name__r*   r   append
extra_repr
splitlineshasattrr   repr_repr_indentjoin)r   headbodylineliness        r   __repr__zVisionDataset.__repr__E   s    DNN333((89:99 KK/$))56!,,..4&4??+FT$//*++DTJT# 1 11D8JJyy Ks   0Cr7   c           
          |j                         j                         }| |d    g|dd  D cg c]   }dj                  dt        |      z  |      " c}z   S c c}w Nr      z{}{}r,   r;   r2   formatlenr   r   r7   r:   r9   s        r   _format_transform_reprz$VisionDataset._format_transform_reprP   `    ""$//1&q
#$Y^_`_aYb'cQUcCIot(L'ccc'c   %Ac                      y)N  r)   s    r   r1   zVisionDataset.extra_reprT   s    r!   )NNNN)r/   
__module____qualname____doc__r5   r	   r   r   r   r   r    intr   r&   r*   r;   r   rC   r1   rH   r!   r   r   r   
   s    $ L "&)-(,/3%CI% X&% H%	%
 #8,% 
%2" " "" "	 # 	 d d dS	 dC r!   r   c                   r    e Zd Zddee   dee   ddfdZdededeeef   fdZded	e	de
e	   fd
Zde	fdZy)r   Nr   r   r   c                      || _         || _        y r(   r   r   )r   r   r   s      r   r    zStandardTransform.__init__Y   s    " 0r!   inputtargetc                 ~    | j                   | j                  |      }| j                  | j                  |      }||fS r(   rO   )r   rP   rQ   s      r   __call__zStandardTransform.__call__]   s@    >>%NN5)E  ,**62Ff}r!   r7   c           
          |j                         j                         }| |d    g|dd  D cg c]   }dj                  dt        |      z  |      " c}z   S c c}w r=   r?   rB   s        r   rC   z(StandardTransform._format_transform_reprd   rD   rE   c                     | j                   j                  g}| j                  || j                  | j                  d      z  }| j                  || j                  | j                  d      z  }dj                  |      S )NzTransform: zTarget transform: r-   )r.   r/   r   rC   r   r6   )r   r8   s     r   r;   zStandardTransform.__repr__h   sq    ''(>>%D//NND  ,D//0E0EG[\\Dyyr!   )NN)r/   rI   rJ   r   r   r    r   r   rS   r   r   rC   r;   rH   r!   r   r   r   X   sx    1(8"4 1xX`Oa 1mq 1c 3 5c? d d dS	 d# r!   r   )r   pathlibr   typingr   r   r   r   r   r	   torch.utils.datautilsdatar   Datasetr   r   rH   r!   r   <module>r\      s7    	  > >   'KDLL K\ r!   