
    ڧg                     r    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dS )    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 fff73e5086ae6bdbea199a49dfb8a4c1trainr   NF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                                        z   _         j        dz   _         j        d	z   _         j        d
z   _        |r                                                                   st)          d          g  _        g }t-           j         j          j         dz            5 }|D ]t}	|	                                                    d          \  }
} j                             j                            |
|                     |                    |
           u	 d d d            n# 1 swxY w Y   t7          t9          |                     _        t=          t?           j        tA          tC           j                                                 _"         fd|D              _#        d S )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/c                 *    g | ]}j         |         S  )class_to_idx).0clsselfs     T/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/dtd.py
<listcomp>z DTD.__init__.<locals>.<listcomp>J   s!    BBB3)#.BBB    )$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lenr!   _labels)r$   r   r   r   r   r   r   rB   fileliner#   name	__class__s   `           r%   r.   zDTD.__init__#   s    %UG5MNN)S)) 	1	3G3G3G3GR3G3G3G3G/$/ / /   $EUVVV#L33d4jj6I6O6O6Q6QQ -5 -8"/(: 	NN!!## 	^\]]]$#&Kdo&K&K&KKLL 	$PT $ $ JJLL..s33	T!(()<)E)Ec4)P)PQQQs####$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ c'll++ T\5T\9J9J3K3K!L!LMMBBBB'BBBs   A8GG!Gc                 *    t          | j                  S N)rF   r;   r$   s    r%   __len__zDTD.__len__L   s    4$%%%r'   idxc                    | j         |         | j        |         }}t          j                            |                              d          }| j        r|                     |          }| j        r|                     |          }||fS )NRGB)r;   rG   PILImager<   convertr   r   )r$   rP   
image_filelabelimages        r%   __getitem__zDTD.__getitem__O   s~     -c2DL4EE
	z**22599> 	*NN5))E  	1))%00Ee|r'   c                 &    d| j          d| j         S )Nzsplit=z, partition=)r(   r,   rN   s    r%   
extra_reprzDTD.extra_repr[   s    BBBBBBr'   c                     t           j                            | j                  o#t           j                            | j                  S rM   )ospathexistsr5   isdirrN   s    r%   r9   zDTD._check_exists^   s/    w~~d/00URW]]4CT5U5UUr'   c                     |                                  rd S t          | j        t          | j                  | j                   d S )N)download_rootmd5)r9   r	   _URLstrr4   _MD5rN   s    r%   r8   zDTD._downloada   sG     	F$TYc$BS>T>TZ^Zcddddddr'   )r   r   NNF)r   N)r2   
__module____qualname____doc__rd   rf   r   re   r/   r0   r*   r   r   boolr.   rO   r   r   rY   r[   r9   r8   __classcell__)rK   s   @r%   r   r      st        ( RD-D
 (,/3'C 'CC%&'C 'C 	'C
 H%'C #8,'C 'C 
'C 'C 'C 'C 'C 'CR& & & & &
s 
uS#X 
 
 
 
CC C C C CVt V V V Ve e e e e e e er'   r   )r]   r/   typingr   r   r   r   r   	PIL.ImagerS   utilsr	   r
   visionr   r   r    r'   r%   <module>rp      s    				  8 8 8 8 8 8 8 8 8 8 8 8 8 8     ? ? ? ? ? ? ? ? ! ! ! ! ! !Ye Ye Ye Ye Ye- Ye Ye Ye Ye Yer'   