
    YhD                     r    d dl Z d dlZd dl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dS )	    N)AnyCallableOptional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                                        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     j/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torchvision/datasets/dtd.py
<listcomp>z DTD.__init__.<locals>.<listcomp>N   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"   _labelsr   )r%   r   r   r   r   r   r   r   rC   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)rG   r<   r%   s    r&   __len__zDTD.__len__Q   s    4$%%%r(   idxc                     | j         |         | j        |         }}|                     |          }| j        r|                     |          }| j        r|                     |          }||fS rN   )r<   rH   r   r   r   )r%   rQ   
image_filelabelimages        r&   __getitem__zDTD.__getitem__T   sn     -c2DL4EE
J''> 	*NN5))E  	1))%00Ee|r(   c                 &    d| j          d| j         S )Nzsplit=z, partition=)r)   r-   rO   s    r&   
extra_reprzDTD.extra_repr`   s    BBBBBBr(   c                     t           j                            | j                  o#t           j                            | j                  S rN   )ospathexistsr6   isdirrO   s    r&   r:   zDTD._check_existsc   s/    w~~d/00URW]]4CT5U5UUr(   c                     |                                  rd S t          | j        t          | j                  | j                   d S )N)download_rootmd5)r:   r	   _URLstrr5   _MD5rO   s    r&   r9   zDTD._downloadf   sG     	F$TYc$BS>T>TZ^Zcddddddr(   )r   N)r3   
__module____qualname____doc__ra   rc   r   r   rb   r0   r1   r+   r   r   boolr   r/   rP   tuplerV   rX   r:   r9   __classcell__)rL   s   @r&   r   r      s        . RD-D
 (,/3<J) )C%&) ) 	)
 H%) #8,) ) %W\ 123S89) 
) ) ) ) ) )V& & & & &
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   )rZ   r0   typingr   r   r   r   folderr   utilsr	   r
   visionr   r   r!   r(   r&   <module>rn      s    				  1 1 1 1 1 1 1 1 1 1 1 1 " " " " " " ? ? ? ? ? ? ? ? ! ! ! ! ! !^e ^e ^e ^e ^e- ^e ^e ^e ^e ^er(   