o
    ôj[  ã                   @   s�   d dl Z d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZ ddlmZ ddlmZmZmZ dd	lmZ G d
d„ deƒZdS )é    N)Úpath)ÚPath)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnion)Úurljoiné   )Údefault_loader)Úcheck_integrityÚdownload_and_extract_archiveÚverify_str_arg)ÚVisionDatasetc                       sŒ  e Zd ZdZdZdZdddœZdZdd	d
dœZdddddddœZ	ddddde
fdeeef dedededee dee deegef ddf‡ fdd„Zdedeeef fd d!„Zdefd"d#„Zedefd$d%„ƒZedefd&d'„ƒZd9dedeee eeef f fd)d*„Zd9dedeeeeef  ee f fd+d,„Zd:d-d.„Zd:d/d0„Zdefd1d2„Z dedefd3d4„Z!d5ed6ededefd7d8„Z"‡  Z#S );Ú	Places365aá  `Places365 <http://places2.csail.mit.edu/index.html>`_ classification dataset.

    Args:
        root (str or ``pathlib.Path``): Root directory of the Places365 dataset.
        split (string, optional): The dataset split. Can be one of ``train-standard`` (default), ``train-challenge``,
            ``val``.
        small (bool, optional): If ``True``, uses the small images, i.e. resized to 256 x 256 pixels, instead of the
            high resolution ones.
        download (bool, optional): If ``True``, downloads the dataset components and places them in ``root``. Already
            downloaded archives are not downloaded again.
        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.
        loader (callable, optional): A function to load an image given its path.

     Attributes:
        classes (list): List of the class names.
        class_to_idx (dict): Dict with items (class_name, class_index).
        imgs (list): List of (image path, class_index) tuples
        targets (list): The class_index value for each image in the dataset

    Raises:
        RuntimeError: If ``download is False`` and the meta files, i.e. the devkit, are not present or corrupted.
        RuntimeError: If ``download is True`` and the image archive is already extracted.
    )útrain-standardútrain-challengeÚvalz+http://data.csail.mit.edu/places/places365/)zfilelist_places365-standard.tarZ 35a0585fee1fa656440f3ab298f8479c)z filelist_places365-challenge.tarZ 70a8307e459c3de41690a7c76c931734)ÚstandardÚ	challenge)zcategories_places365.txtZ 06c963b85866bd0649f97cb43dd16673)zplaces365_train_standard.txtZ 30f37515461640559006b8329efbed1a)zplaces365_train_challenge.txtZ b2931dc997b8c33c27e7329c073a6b57)zplaces365_val.txtZ e9f2fd57bfd9d07630173f4e8708e4b1)z!train_large_places365standard.tarZ 67e186b496a84c929568076ed01a8aa1)z"train_large_places365challenge.tarZ 605f18e68e510c82b958664ea134545f)zval_large.tarZ 9b71c4993ad89d2d8bcbdc4aef38042f)ztrain_256_places365standard.tarZ 53ca1c756c3d1e7809517cc47c5561c5)z train_256_places365challenge.tarZ 741915038a5e3471ec7332404dfb64ef)zval_256.tarZ e27b17d8d44f4af9a78502beb927f808))r   F)r   F)r   F)r   T)r   T)r   Tr   FNÚrootÚsplitÚsmallÚdownloadÚ	transformÚtarget_transformÚloaderÚreturnc                    sb   t ƒ j|||d� |  |¡| _|| _|| _|  |¡\| _| _|  	|¡\| _
| _|r/|  ¡  d S d S )N)r   r   )ÚsuperÚ__init__Ú_verify_splitr   r   r   Úload_categoriesÚclassesÚclass_to_idxÚload_file_listÚimgsÚtargetsÚdownload_images)Úselfr   r   r   r   r   r   r   ©Ú	__class__© úo/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torchvision/datasets/places365.pyr!   @   s   
ÿzPlaces365.__init__Úindexc                 C   s:   | j | \}}|  |¡}| jd ur|  ||¡\}}||fS ©N)r'   r   Ú
transforms)r*   r/   ÚfileÚtargetÚimager-   r-   r.   Ú__getitem__V   s
   

zPlaces365.__getitem__c                 C   s
   t | jƒS r0   )Úlenr'   ©r*   r-   r-   r.   Ú__len___   s   
zPlaces365.__len__c                 C   s   d| j v rdS dS )Nr   r   )r   r7   r-   r-   r.   Úvariantb   s   zPlaces365.variantc                 C   sL   | j rdnd}| j d¡rd|› d| j› �}n| j› d|› �}t | j|¡S )NÚ256ÚlargeÚtrainZdata_Ú_)r   r   Ú
startswithr9   r   Újoinr   )r*   ÚsizeÚdirr-   r-   r.   Ú
images_dirf   s
   zPlaces365.images_dirTc                    s–   dt dtt tf fdd„‰ | j\}}t | j|¡}|  |||¡s$|  ¡  t	|ƒ�}t
‡ fdd„|D ƒƒ}W d   ƒ n1 s>w   Y  t| ¡ ƒ|fS )NÚliner   c                 S   s   |   ¡ \}}|t|ƒfS r0   )r   Úint)rC   ÚclsÚidxr-   r-   r.   Úprocessp   s   z*Places365.load_categories.<locals>.processc                 3   s   � | ]}ˆ |ƒV  qd S r0   r-   ©Ú.0rC   ©rG   r-   r.   Ú	<genexpr>z   s   € z,Places365.load_categories.<locals>.<genexpr>)Ústrr	   rD   Ú_CATEGORIES_METAr   r?   r   Ú_check_integrityÚdownload_devkitÚopenÚdictÚsortedÚkeys)r*   r   r2   Úmd5Úfhr%   r-   rJ   r.   r#   o   s   

ÿzPlaces365.load_categoriesc                    s¦   ddt dtt tf f‡fdd„‰ ˆjˆj \}}t ˆj|¡}ˆ |||¡s*ˆ 	¡  t
|ƒ�}‡ fdd„|D ƒ}W d   ƒ n1 sBw   Y  t|Ž \}}|t|ƒfS )	Nú/rC   r   c                    s2   |   ¡ \}}t ˆ j| |¡ |tj¡¡t|ƒfS r0   )	r   r   r?   rB   ÚlstripÚreplaceÚosÚseprD   )rC   rZ   r4   rF   r7   r-   r.   rG      s   &z)Places365.load_file_list.<locals>.processc                    s   g | ]}ˆ |ƒ‘qS r-   r-   rH   rJ   r-   r.   Ú
<listcomp>‰   s    z,Places365.load_file_list.<locals>.<listcomp>)rV   )rL   r	   rD   Ú_FILE_LIST_METAr   r   r?   r   rN   rO   rP   ÚzipÚlist)r*   r   r2   rT   rU   Úimagesr=   r(   r-   )rG   r*   r.   r&   ~   s    
ÿzPlaces365.load_file_listc                 C   s,   | j | j \}}tt| j|ƒ| j|d� d S )N©rT   )Ú_DEVKIT_METAr9   r   r   Ú	_BASE_URLr   ©r*   r2   rT   r-   r-   r.   rO   Ž   s   zPlaces365.download_devkitc                 C   s|   t  | j¡rtd| j› d�ƒ‚| j| j| jf \}}tt| j	|ƒ| j
|d� | j d¡r<t | j dd¡d | j¡ d S d S )NzThe directory z[ already exists. If you want to re-download or re-extract the images, delete the directory.r`   r<   r=   r   r   )r   ÚexistsrB   ÚRuntimeErrorÚ_IMAGES_METAr   r   r   r   rb   r   r>   rY   ÚrenameÚrsplitrc   r-   r-   r.   r)   ’   s   ÿ ÿzPlaces365.download_imagesc                 C   s   d  d¡jdi | j¤ŽS )NÚ
)zSplit: {split}zSmall: {small}r-   )r?   ÚformatÚ__dict__r7   r-   r-   r.   Ú
extra_reprŸ   s   zPlaces365.extra_reprc                 C   s   t |d| jƒS )Nr   )r   Ú_SPLITS)r*   r   r-   r-   r.   r"   ¢   s   zPlaces365._verify_splitr2   rT   c                 C   s(   t ||d�}|s|std|› d�ƒ‚|S )Nr`   z	The file zJ does not exist or is corrupted. You can set download=True to download it.)r   re   )r*   r2   rT   r   Z	integrityr-   r-   r.   rN   ¥   s   
ÿzPlaces365._check_integrity)T)r   N)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__rm   rb   ra   rM   r\   rf   r   r
   rL   r   Úboolr   r   r   r!   rD   r	   r5   r8   Úpropertyr9   rB   r   r   r#   r&   rO   r)   rl   r"   rN   Ú__classcell__r-   r-   r+   r.   r      sn    þýúø
þýüûúùø	÷	(,

"r   )rY   r   Úpathlibr   Útypingr   r   r   r   r   r	   r
   Úurllib.parser   Úfolderr   Úutilsr   r   r   Úvisionr   r   r-   r-   r-   r.   Ú<module>   s    $