
    ,}h                     j    d dl Z d dlZd dlmZmZmZmZmZ d dl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   )download_and_extract_archiveverify_str_arg)VisionDatasetc                        e Zd ZdZdZdZ	 	 	 	 	 ddeeej                  f   dede
dee   d	ee   d
e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 )DTDaN  `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 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.
    zDhttps://www.robots.ox.ac.uk/~vgg/data/dtd/download/dtd-r1.0.1.tar.gz fff73e5086ae6bdbea199a49dfb8a4c1Nrootsplit	partition	transformtarget_transformdownload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   )train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_labels)selfr   r   r   r   r   r   r9   filelineclsname	__class__s               W/var/www/html/test/engine/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   A0H9I9Ic                 ,    t        | j                        S N)r=   r2   r@   s    rF   __len__zDTD.__len__L   s    4$$%%    idxc                    | j                   |   | j                  |   }}t        j                  j	                  |      j                  d      }| j                  r| j                  |      }| j                  r| j                  |      }||fS )NRGB)r2   r?   PILImager3   convertr   r   )r@   rL   
image_filelabelimages        rF   __getitem__zDTD.__getitem__O   st     --c2DLL4EE
		z*2259>>NN5)E  ))%0Ee|rK   c                 :    d| j                    d| j                   S )Nzsplit=z, partition=)r   r#   rI   s    rF   
extra_reprzDTD.extra_repr[   s    }L0ABBrK   c                     t         j                  j                  | j                        xr) t         j                  j	                  | j                        S rH   )ospathexistsr,   isdirrI   s    rF   r0   zDTD._check_exists^   s3    ww~~d//0URWW]]4CTCT5UUrK   c                     | j                         ry t        | j                  t        | j                        | j
                         y )N)download_rootmd5)r0   r	   _URLstrr+   _MD5rI   s    rF   r/   zDTD._downloada   s3    $TYYc$BSBS>TZ^ZcZcdrK   )r   r   NNF)r   N)r)   
__module____qualname____doc__r`   rb   r   ra   r&   r'   r!   r   r   boolr%   rJ   r   r   rU   rW   r0   r/   __classcell__)rE   s   @rF   r   r      s    ( RD-D
 (,/3'CC%&'C 'C 	'C
 H%'C #8,'C 'C 
'CR& &
s 
uS#X 
CC CVt VerK   r   )rY   r&   typingr   r   r   r   r   	PIL.ImagerO   utilsr	   r
   visionr   r    rK   rF   <module>rm      s*    	  8 8  ? !Ye- YerK   