
    khK                     n    d dl Z d dlZd dlmZmZmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ  G d de      Zy)	    N)AnyCallableOptionalTupleUnion   )default_loader)download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZdddddefdeee	j                  f   d	ed
edee   dee   dedeeee	j                  f   gef   ddf fdZdefdZdedeeef   fdZdefdZdefdZddZ xZS )DTDa}  `Describable Textures Dataset (DTD) <https://www.robots.ox.ac.uk/~vgg/data/dtd/>`_.

    Args:
        root (str or ``pathlib.Path``): Root directory of the dataset.
        split (string, optional): The dataset split, supports ``"train"`` (default), ``"val"``, or ``"test"``.
        partition (int, optional): The dataset partition. Should be ``1 <= partition <= 10``. Defaults to ``1``.

            .. note::

                The partition only changes which split each image belongs to. Thus, regardless of the selected
                partition, combining all splits will result in all images.

        transform (callable, optional): A function/transform that takes in a PIL image or torch.Tensor, depends on the given loader,
            and returns a transformed version. E.g, ``transforms.RandomCrop``
        target_transform (callable, optional): A function/transform that takes in the target and transforms it.
        download (bool, optional): If True, downloads the dataset from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again. Default is False.
        loader (callable, optional): A function to load an image given its path.
            By default, it uses PIL as its image loader, but users could also pass in
            ``torchvision.io.decode_image`` for decoding image data into tensors directly.
    zDhttps://www.robots.ox.ac.uk/~vgg/data/dtd/download/dtd-r1.0.1.tar.gz fff73e5086ae6bdbea199a49dfb8a4c1trainr   NFrootsplit	partition	transformtarget_transformdownloadloaderreturnc           
         t        |dd      | _        t        |t              sd|cxk  rdk  sn t	        d| d      || _        t        |   |||       t        j                  | j                        t        |       j                  j                         z  | _        | j                  dz  | _        | j                  d	z  | _        | j                  d
z  | _        |r| j%                          | j'                         st)        d      g | _        g }t-        | j                   | j                   | j
                   dz        5 }	|	D ]j  }
|
j/                         j1                  d      \  }}| j*                  j3                  | j"                  j5                  ||             |j3                  |       l 	 d d d        t7        t9        |            | _        t=        t?        | j:                  tA        tC        | j:                                          | _"        |D cg c]  }| jD                  |    c}| _#        || _$        y # 1 sw Y   xY wc c}w )Nr   )r   valtestr   
   zPParameter 'partition' should be an integer with `1 <= partition <= 10`, but got z instead)r   r   dtdlabelsimagesz;Dataset not found. You can use download=True to download itz.txt/)%r   _split
isinstanceint
ValueError
_partitionsuper__init__pathlibPathr   type__name__lower_base_folder_data_folder_meta_folder_images_folder	_download_check_existsRuntimeError_image_filesopenstripr   appendjoinpathsortedsetclassesdictziprangelenclass_to_idx_labelsr   )selfr   r   r   r   r   r   r   r;   filelineclsname	__class__s                T/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/dtd.pyr'   zDTD.__init__&   s    %UG5MN)S)1	3GR3G$+X/  $EUV#LL3d4j6I6I6O6O6QQ --5 --8"//(:NN!!#\]]$##doo5Fd&KKL 	$PT $ JJL..s3	T!!(()<)<)E)Ec4)PQs#$	$ c'l+ T\\5T\\9J3K!LM:AB3))#.B	$ 	$ Cs   A0I I I	c                 ,    t        | j                        S N)r?   r4   rB   s    rH   __len__zDTD.__len__Q   s    4$$%%    idxc                     | j                   |   | j                  |   }}| j                  |      }| j                  r| j                  |      }| j                  r| j	                  |      }||fS rJ   )r4   rA   r   r   r   )rB   rN   
image_filelabelimages        rH   __getitem__zDTD.__getitem__T   se     --c2DLL4EE
J'>>NN5)E  ))%0Ee|rM   c                 :    d| j                    d| j                   S )Nzsplit=z, partition=)r!   r%   rK   s    rH   
extra_reprzDTD.extra_repr`   s    }L0ABBrM   c                     t         j                  j                  | j                        xr) t         j                  j	                  | j                        S rJ   )ospathexistsr.   isdirrK   s    rH   r2   zDTD._check_existsc   s3    ww~~d//0URWW]]4CTCT5UUrM   c                     | j                         ry t        | j                  t        | j                        | j
                         y )N)download_rootmd5)r2   r
   _URLstrr-   _MD5rK   s    rH   r1   zDTD._downloadf   s3    $TYYc$BSBS>TZ^ZcZcdrM   )r   N)r+   
__module____qualname____doc__r^   r`   r	   r   r_   r(   r)   r#   r   r   boolr   r'   rL   r   rS   rU   r2   r1   __classcell__)rG   s   @rH   r   r      s    . RD-D
 (,/3<J)C%&) ) 	)
 H%) #8,) ) %W\\ 123S89) 
)V& &
s 
uS#X 
CC CVt VerM   r   )rW   r(   typingr   r   r   r   r   folderr	   utilsr
   r   visionr   r    rM   rH   <module>rk      s*    	  8 8 " ? !^e- ^erM   