o
    )i                     @   s`   d dl Z d dlZd dl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 deZdS )    N)AnyCallableOptionalTuple   )download_and_extract_archiveverify_str_arg)VisionDatasetc                       s   e Zd ZdZdZdZ					dded	ed
edee	 dee	 de
ddf fddZdefddZdedeeef fddZdefddZde
fddZdddZ  ZS )DTDa>  `Describable Textures Dataset (DTD) <https://www.robots.ox.ac.uk/~vgg/data/dtd/>`_.

    Args:
        root (string): 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.gzZ fff73e5086ae6bdbea199a49dfb8a4c1trainr   NFrootsplit	partition	transformtarget_transformdownloadreturnc                    sv  t |dd _t|tsd|  krdksn td| d| _t j|||d t	 j
t j   _ jd  _ jd	  _ jd
  _|rQ     sYtdg  _g }t j j  j d &}|D ]}	|	 d\}
} j j|
| ||
 qoW d    n1 sw   Y  tt| _tt jt t! j _" fd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labelsZimagesz;Dataset not found. You can use download=True to download itz.txt/c                    s   g | ]} j | qS  )class_to_idx).0clsselfr   g/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torchvision/datasets/dtd.py
<listcomp>J   s    z DTD.__init__.<locals>.<listcomp>)$r   _split
isinstanceint
ValueError
_partitionsuper__init__pathlibPathr   type__name__lower_base_folder_data_folderZ_meta_folderZ_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   r9   fileliner   name	__class__r   r   r'   #   s:   	 zDTD.__init__c                 C   s
   t | jS N)r=   r2   r   r   r   r   __len__L   s   
zDTD.__len__idxc                 C   sP   | j | | j| }}tj|d}| jr| |}| jr$| |}||fS )NRGB)r2   r>   PILZImager3   convertr   r   )r   rF   Z
image_filelabelimager   r   r   __getitem__O   s   

zDTD.__getitem__c                 C   s   d| j  d| j S )Nzsplit=z, partition=)r!   r%   r   r   r   r   
extra_repr[   s   zDTD.extra_reprc                 C   s   t j| jot j| jS rD   )ospathexistsr.   isdirr   r   r   r   r0   ^   s   zDTD._check_existsc                 C   s(   |   rd S t| jt| j| jd d S )N)Zdownload_rootmd5)r0   r   _URLstrr-   _MD5r   r   r   r   r/   a   s   zDTD._download)r   r   NNF)r   N)r+   
__module____qualname____doc__rS   rU   rT   r#   r   r   boolr'   rE   r   r   rL   rM   r0   r/   __classcell__r   r   rB   r   r
      s:    )r
   )rN   r(   typingr   r   r   r   Z	PIL.ImagerH   utilsr   r   Zvisionr	   r
   r   r   r   r   <module>   s    