Ë
    Dêñi+  ã                   óŽ   — 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y)é    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d/dedeee   eeef   f   fd&„Z	 d/dedeeeeeedf   f      eeedf      f   fd'„Zd0d(„Zd0d)„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 )1Ú	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                 ó  •— t         ‰| �  |||¬«       | j                  |«      | _        || _        || _        | j                  |«      \  | _        | _        | j                  |«      \  | _
        | _        |r| j                  «        y y )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	           €ú`/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/torchvision/datasets/places365.pyr2   zPlaces365.__init__D   s�   ø€ ô 	‰Ñ˜¨ÐEUÐÔVà×'Ñ'¨Ó.ˆŒ
ØˆŒ
ØˆŒà*.×*>Ñ*>¸xÓ*HÑ'ˆŒ�dÔ'Ø"&×"5Ñ"5°hÓ"?ÑˆŒ	�4”<áØ× Ñ Õ"ð ó    Úindexc                 ó’   — | j                   |   \  }}| j                  |«      }| j                  �| j                  ||«      \  }}||fS ©N)r8   r.   Ú
transforms)r;   r?   ÚfileÚtargetÚimages        r=   Ú__getitem__zPlaces365.__getitem__Z   sJ   € Ø—y‘y Ñ'‰ˆˆfØ—‘˜DÓ!ˆà�?‰?Ð&Ø ŸO™O¨E°6Ó:‰MˆE�6à�fˆ}Ðr>   c                 ó,   — t        | j                  «      S rA   )Úlenr8   ©r;   s    r=   Ú__len__zPlaces365.__len__c   s   € Ü�4—9‘9‹~Ðr>   c                 ó&   — d| j                   v rdS dS )Nr   r   )r)   rI   s    r=   ÚvariantzPlaces365.variantf   s   € à)¨T¯Z©ZÑ7ˆ{ÐG¸ZÐGr>   c                 óà   — | j                   rdnd}| j                  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   s`   € àŸ
š
‰u¨ˆØ�:‰:× Ñ  Ô)Ø˜$˜˜q §¡ Ð/‰Cà—Z‘Z�L  $ Ð(ˆCÜ�y‰y˜Ÿ™ CÓ(Ð(r>   c                 ó€  ‡— dt         dt        t         t        f   fd„Š| j                  \  }}t	        j
                  | j                  |«      }| j                  |||«      s| j                  «        t        |«      5 }t        ˆfd„|D «       «      }d d d «       t        j                  «       «      |fS # 1 sw Y   Œ$xY w)NÚliner/   c                 óB   — | j                  «       \  }}|t        |«      fS rA   )r)   Úint)rY   ÚclsÚidxs      r=   Úprocessz*Places365.load_categories.<locals>.processt   s   € Ø—z‘z“|‰HˆC�Øœ˜C›�=Ð r>   c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wrA   © )Ú.0rY   r^   s     €r=   ú	<genexpr>z,Places365.load_categories.<locals>.<genexpr>~   s   øè ø€ Ò=°$¡¨§Ñ=ùs   ƒ)Ú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‰y˜Ÿ™ DÓ)ˆØ×$Ñ$ T¨3°Ô9Ø× Ñ Ô"ä�$‹Zð 	>˜2ÜÓ=¸"Ô=Ó=ˆL÷	>ô �l×'Ñ'Ó)Ó*¨LÐ8Ð8÷	>ð 	>ús   Á<B4Â4B=c           	      ó¸  ‡ — ddt         dt        t         t        t        d f   f   fˆ fd„}‰ j                  ‰ j
                     \  }}t        j                  ‰ j                  |«      }‰ j                  |||«      s‰ j                  «        t        |«      5 }|D �cg c]
  } ||«      ‘Œ }}d d d «       t        Ž \  }}	|t        |	«      fS c c}w # 1 sw Y   Œ&xY w)NrY   r/   c                 ó  •— | j                  «       d gz   d d \  }}t        t        |«      }|�t        |«      nd }t	        j
                  ‰j                  |j                  |«      j                  |t        j                  «      «      |fS )Né   )r)   r   rc   r[   r   rT   rW   ÚlstripÚreplaceÚosÚsep)rY   rt   rE   r]   r;   s       €r=   r^   z)Places365.load_file_list.<locals>.process…   sp   ø€ ØŸ*™*›,¨$¨Ñ/°°!Ð4‰JˆE�3Üœ˜eÓ$ˆEØ!˜o”#�c”(°4ˆCÜ—9‘9˜TŸ_™_¨e¯l©l¸3Ó.?×.GÑ.GÈÌRÏVÉVÓ.TÓUÐWZÐZÐZr>   )ú/)rc   rd   r	   r[   Ú_FILE_LIST_METAr)   r   rT   r(   rf   rg   rh   ÚzipÚlist)
r;   r+   r^   rC   rl   rm   rY   ÚimagesrR   r9   s
   `         r=   r7   zPlaces365.load_file_list‚   sÐ   ø€ ñ	[œ#ð 	[¬5´´e¼CÀ¸IÑ6FÐ1FÑ+Gõ 	[ð ×(Ñ(¨¯©Ñ4‰	ˆˆcÜ�y‰y˜Ÿ™ DÓ)ˆØ×$Ñ$ T¨3°Ô9Ø× Ñ Ô"ä�$‹Zð 	4˜2Ø02Ö3¨‘g˜d•mÐ3ˆFÐ3÷	4ô ˜&�\‰
ˆˆ7Ø”t˜G“}Ð$Ð$ùò 4÷	4ð 	4ús   ÂCÂCÂ)CÃCÃCc                 ó”   — | j                   | j                     \  }}t        t        | j                  |«      | j
                  |¬«       y )N©rl   )Ú_DEVKIT_METArL   r   r
   Ú	_BASE_URLr(   ©r;   rC   rl   s      r=   rg   zPlaces365.download_devkit–   s6   € Ø×%Ñ% d§l¡lÑ3‰	ˆˆcÜ$¤W¨T¯^©^¸TÓ%BÀDÇIÁIÐSVÖWr>   c                 óž  — t        j                  | j                  «      ry | j                  | j                  | j
                  f   \  }}t        t        | j                  |«      | j                  |¬«       | j                  j                  d«      r>t        j                  | j                  j                  dd«      d   | j                  «       y y )Nr{   rP   rR   r   r   )r   ÚexistsrW   Ú_IMAGES_METAr)   r*   r   r
   r}   r(   rS   rs   ÚrenameÚrsplitr~   s      r=   r:   zPlaces365.download_imagesš   s‘   € Ü�;‰;�t—‘Ô'Øà×%Ñ% t§z¡z°4·:±:Ð&>Ñ?‰	ˆˆcÜ$¤W¨T¯^©^¸TÓ%BÀDÇIÁIÐSVÕWà�:‰:× Ñ  Ô)Ü�I‰I�d—o‘o×,Ñ,¨S°!Ó4°QÑ7¸¿¹ÕIð *r>   c                 óX   —  dj                  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&   € ØEˆt�y‰yÐ=Ó>×EÑEÑVÈÏÉÑVÐVr>   c                 ó0   — t        |d| j                  «      S )Nr)   )r   Ú_SPLITS)r;   r)   s     r=   r3   zPlaces365._verify_split§   s   € Ü˜e W¨d¯l©lÓ;Ð;r>   rC   rl   c                 óF   — 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   rl   r+   Ú	integritys        r=   rf   zPlaces365._check_integrityª   s5   € Ü# D¨cÔ2ˆ	Ù¡ÜØ˜D˜6Ð!kÐlóð ð Ðr>   )T)r/   N)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__rŠ   r}   r|   re   rv   r�   r   r	   rc   r   Úboolr   r   r   r2   r[   rd   rF   rJ   ÚpropertyrL   rW   rx   ri   r4   r7   rg   r:   rˆ   r3   rf   Ú__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Ñ,ð#ð ˜#˜ ˜Ñ$ð#ð 
õ#ð, ð ¨¨s°C¨x©ó ð˜ó ð ðH˜ò Hó ðHð ð)˜Cò )ó ð)ñ9¨ð 9¸¸dÀ3¹iÈÈcÐSVÈhÉÐ>WÑ8Xó 9ð   $ñ%Øð%à	ˆt�E˜#˜u S¨$ YÑ/Ð/Ñ0Ñ1°4¸¸cÀ4¸iÑ8HÑ3IÐIÑ	Jó%ó(XóJðW˜Có Wð< 3ð <¨3ó <ð Sð ¨sð ¸dð Àt÷ r>   r   )rs   r   Úpathlibr   Útypingr   r   r   r   r	   Úurllib.parser
   Úfolderr   Úutilsr   r   r   Úvisionr   r   r`   r>   r=   ú<module>r›      s1   ðÛ 	Ý Ý ß 7Õ 7Ý  å "ß PÑ PÝ !ôd�õ dr>   