
    Yh+                         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	 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e          ZdS )    N)path)Path)AnyCallablecastOptionalUnion)urljoin   )default_loader)check_integritydownload_and_extract_archiveverify_str_arg)VisionDatasetc                       e Zd ZdZdZdZdddZdZdd	d
ddZdd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 Zd!edeeef         fd"Zdefd#Zedefd$            Zedefd%            Zd0dedeee         eeef         f         fd'Z	 d0dedeeeeeedf         f                  eeedf                  f         fd(Zd1d)Zd1d*Zdefd+Z dedefd,Z!d-ed.ededefd/Z" xZ#S )2	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``, ``test``.
        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valtestz+http://data.csail.mit.edu/places/places365/)zfilelist_places365-standard.tar 35a0585fee1fa656440f3ab298f8479c)z filelist_places365-challenge.tar 70a8307e459c3de41690a7c76c931734)standard	challenge)zcategories_places365.txt 06c963b85866bd0649f97cb43dd16673)zplaces365_train_standard.txt 30f37515461640559006b8329efbed1a)zplaces365_train_challenge.txt b2931dc997b8c33c27e7329c073a6b57)zplaces365_val.txt e9f2fd57bfd9d07630173f4e8708e4b1)zplaces365_test.txt 2fce8233fe493576d724142e45d93653)z!train_large_places365standard.tar 67e186b496a84c929568076ed01a8aa1)z"train_large_places365challenge.tar 605f18e68e510c82b958664ea134545f)zval_large.tar 9b71c4993ad89d2d8bcbdc4aef38042f)ztest_large.tar 41a4b6b724b1d2cd862fb3871ed59913)ztrain_256_places365standard.tar 53ca1c756c3d1e7809517cc47c5561c5)z train_256_places365challenge.tar 741915038a5e3471ec7332404dfb64ef)zval_256.tar e27b17d8d44f4af9a78502beb927f808)ztest_256.tar f532f6ad7b582262a2ec8009075e186b))r   F)r   F)r   F)r   F)r   T)r   T)r   T)r   Tr   FNrootsplitsmalldownload	transformtarget_transformloaderreturnc                 X   t                                          |||           |                     |          | _        || _        || _        |                     |          \  | _        | _        | 	                    |          \  | _
        | _        |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__s	           p/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torchvision/datasets/places365.pyr2   zPlaces365.__init__D   s     	EUVVV''..

*.*>*>x*H*H'd'"&"5"5h"?"?	4< 	#  """""	# 	#    indexc                     | j         |         \  }}|                     |          }| j        |                     ||          \  }}||fS N)r8   r.   
transforms)r;   r?   filetargetimages        r=   __getitem__zPlaces365.__getitem__Z   sL    y'fD!!?& OOE6::ME6f}r>   c                 *    t          | j                  S rA   )lenr8   r;   s    r=   __len__zPlaces365.__len__c   s    49~~r>   c                     d| j         v rdndS )Nr   r   )r)   rI   s    r=   variantzPlaces365.variantf   s    )TZ77{{ZGr>   c                     | j         rdnd}| j                            d          rd| d| j         }n| j         d| }t	          j        | j        |          S )N256largetraindata__)r*   r)   
startswithrL   r   joinr(   )r;   sizedirs      r=   
images_dirzPlaces365.images_dirj   sl    
/uu:  )) 	)/$////CCZ(($((CyC(((r>   Tc                    dt           dt          t           t          f         fd| j        \  }}t	          j        | j        |          }|                     |||          s|                                  t          |          5 }t          fd|D                       }d d d            n# 1 swxY w Y   t          |                                          |fS )Nliner/   c                 R    |                                  \  }}|t          |          fS rA   )r)   int)rY   clsidxs      r=   processz*Places365.load_categories.<locals>.processt   s#    zz||HCC= r>   c              3   .   K   | ]} |          V  d S rA    .0rY   r^   s     r=   	<genexpr>z,Places365.load_categories.<locals>.<genexpr>~   s+      ==$======r>   )strtupler[   _CATEGORIES_METAr   rT   r(   _check_integritydownload_devkitopendictsortedkeys)r;   r+   rC   md5fhr6   r^   s         @r=   r4   zPlaces365.load_categoriess   s   	!# 	!%S/ 	! 	! 	! 	! )	cyD))$$T399 	#  """$ZZ 	>2===="=====L	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> l''))**L88s   B,,B03B0c           	          ddt           dt          t           t          t          d f         f         f fd j         j                 \  }}t          j         j        |          } 	                    |||          s 
                                 t          |          5 }fd|D             }d d d            n# 1 swxY w Y   t          | \  }}|t          |          fS )N/rY   r/   c                 4   |                                  d gz   d d         \  }}t          t          |          }|t          |          nd }t	          j        j        |                    |                              |t          j
                            |fS )N   )r)   r   rd   r[   r   rT   rW   lstripreplaceossep)rY   rv   rE   r]   r;   s       r=   r^   z)Places365.load_file_list.<locals>.process   s~    **,,$/!4JE3e$$E!o#c(((4C9T_ell3.?.?.G.GRV.T.TUUWZZZr>   c                 &    g | ]} |          S r`   r`   ra   s     r=   
<listcomp>z,Places365.load_file_list.<locals>.<listcomp>   s!    333ggdmm333r>   )rp   )rd   re   r	   r[   _FILE_LIST_METAr)   r   rT   r(   rg   rh   ri   ziplist)	r;   r+   rC   rm   rn   imagesrR   r9   r^   s	   `       @r=   r7   zPlaces365.load_file_list   s<   	[ 	[# 	[5eCI6F1F+G 	[ 	[ 	[ 	[ 	[ 	[ (4	cyD))$$T399 	#  """$ZZ 	423333333F	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 &\
7tG}}$$s    B;;B?B?c                     | j         | j                 \  }}t          t          | j        |          | j        |           d S )Nrm   )_DEVKIT_METArL   r   r
   	_BASE_URLr(   r;   rC   rm   s      r=   rh   zPlaces365.download_devkit   s?    %dl3	c$WT^T%B%BDISVWWWWWWr>   c                 r   t          j        | j                  rd S | j        | j        | j        f         \  }}t          t          | j        |          | j	        |           | j        
                    d          r;t          j        | j                            dd          d         | j                   d S d S )Nr~   rP   rR   r   r   )r   existsrW   _IMAGES_METAr)   r*   r   r
   r   r(   rS   ru   renamersplitr   s      r=   r:   zPlaces365.download_images   s    ;t'' 	F%tz4:&>?	c$WT^T%B%BDISVWWWW:  )) 	JIdo,,S!44Q7IIIII	J 	Jr>   c                 L     d                     d          j        di | j        S )N
)zSplit: {split}zSmall: {small}r`   )rT   format__dict__rI   s    r=   
extra_reprzPlaces365.extra_repr   s*    Etyy=>>EVVVVVr>   c                 .    t          |d| j                  S )Nr)   )r   _SPLITS)r;   r)   s     r=   r3   zPlaces365._verify_split   s    eWdl;;;r>   rC   rm   c                 V    t          ||          }|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   RuntimeError)r;   rC   rm   r+   	integritys        r=   rg   zPlaces365._check_integrity   sK    #Dc222	 	 	lDlll   r>   )T)r/   N)$__name__
__module____qualname____doc__r   r   r   rf   ry   r   r   r	   rd   r   boolr   r   r   r2   r[   re   rF   rJ   propertyrL   rW   r{   rj   r4   r7   rh   r:   r   r3   rg   __classcell__)r<   s   @r=   r   r      s        6 CG=I \] L
 X _`HJ	 O $m$nMO"i#kJL	 	L &(,/3'5# #CI# # 	#
 # H%# #8,# #$# 
# # # # # #, sCx         H H H H XH )C ) ) ) X)9 9 9d3icSVh>W8X 9 9 9 9   $% %%	tE#uS$Y//014c4i8H3II	J% % % %(X X X XJ J J JWC W W W W<3 <3 < < < <S s d t        r>   r   )ru   r   pathlibr   typingr   r   r   r   r	   urllib.parser
   folderr   utilsr   r   r   visionr   r   r`   r>   r=   <module>r      s    				             7 7 7 7 7 7 7 7 7 7 7 7 7 7             " " " " " " P P P P P P P P P P ! ! ! ! ! !d d d d d d d d d dr>   