
    QЦi                         S SK r S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
Jr  S SKJr  SSKJr  SSKJrJrJr  SS	KJr   " S
 S\5      rg)    N)path)Path)AnyCallableDictListOptionalTupleUnion)urljoin   )default_loader)check_integritydownload_and_extract_archiveverify_str_arg)VisionDatasetc                     ^  \ rS rSrSrSrSrSSS.rSrS	S
SS.r	SSSSSSS.r
SSSSS\4S\\\4   S\S\S\S\\   S\\   S\\/\4   SS4U 4S jjjrS\S\\\4   4S  jrS\4S! jr\S\4S" j5       r\S\4S# j5       rS.S\S\\\   \\\4   4   4S$ jjrS.S\S\\\\\4      \\   4   4S% jjrS/S& jrS/S' jr S\4S( jr!S\S\4S) jr"S*\S+\S\S\4S, jr#S-r$U =r%$ )0	Places365   a  `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.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!train_large_places365standard.tar 67e186b496a84c929568076ed01a8aa1)z"train_large_places365challenge.tar 605f18e68e510c82b958664ea134545f)zval_large.tar 9b71c4993ad89d2d8bcbdc4aef38042f)ztrain_256_places365standard.tar 53ca1c756c3d1e7809517cc47c5561c5)z train_256_places365challenge.tar 741915038a5e3471ec7332404dfb64ef)zval_256.tar e27b17d8d44f4af9a78502beb927f808))r   F)r   F)r   F)r   T)r   T)r   Tr   FNrootsplitsmalldownload	transformtarget_transformloaderreturnc                   > [         TU ]  XUS9  U R                  U5      U l        X0l        Xpl        U R                  U5      u  U l        U l        U R                  U5      u  U l
        U l        U(       a  U R                  5         g g )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/html/ai-image-ml/venv/lib/python3.13/site-packages/torchvision/datasets/places365.pyr1   Places365.__init__@   s{     	EUV''.

*.*>*>x*H'd'"&"5"5h"?	4<  "     indexc                     U R                   U   u  p#U R                  U5      nU R                  b  U R                  XC5      u  pCXC4$ N)r7   r-   
transforms)r:   r?   filetargetimages        r<   __getitem__Places365.__getitem__V   sB    yy'D!??& OOE:ME}r>   c                 ,    [        U R                  5      $ rA   )lenr7   r:   s    r<   __len__Places365.__len___   s    499~r>   c                 *    SU R                   ;   a  S$ S$ )Nr   r   )r(   rJ   s    r<   variantPlaces365.variantb   s    )TZZ7{GZGr>   c                     U R                   (       a  SOSnU R                  R                  S5      (       a  SU SU R                   3nOU R                   SU 3n[        R
                  " U R                  U5      $ )N256largetraindata__)r)   r(   
startswithrN   r   joinr'   )r:   sizedirs      r<   
images_dirPlaces365.images_dirf   sc    

u::  ))$q/CZZL$(CyyC((r>   c                   ^ S[         S[        [         [        4   4S jmU R                  u  p#[        R
                  " U R                  U5      nU R                  X#U5      (       d  U R                  5         [        U5       n[        U4S jU 5       5      nS S S 5        [        WR                  5       5      U4$ ! , (       d  f       N)= f)Nliner.   c                 @    U R                  5       u  pU[        U5      4$ rA   )r(   int)r]   clsidxs      r<   process*Places365.load_categories.<locals>.processp   s    zz|HCC= r>   c              3   4   >#    U  H  nT" U5      v   M     g 7frA    ).0r]   rb   s     r<   	<genexpr>,Places365.load_categories.<locals>.<genexpr>z   s     ="$"s   )strr
   r_   _CATEGORIES_METAr   rW   r'   _check_integritydownload_devkitopendictsortedkeys)r:   r*   rC   md5fhr5   rb   s         @r<   r3   Places365.load_categorieso   s    	!# 	!%S/ 	! ))	yyD)$$T99  "$Z2="==L  l'')*L88 Zs   B::
Cc                   ^  SS[         S[        [         [        4   4U 4S jjjnT R                  T R                     u  p4[
        R                  " T R                  U5      nT R                  X4U5      (       d  T R                  5         [        U5       nU Vs/ s H
  ob" U5      PM     nnS S S 5        [        W6 u  pU[        U	5      4$ s  snf ! , (       d  f       N*= f)Nr]   r.   c                    > U R                  5       u  p#[        R                  " TR                  UR	                  U5      R                  U[        R                  5      5      [        U5      4$ rA   )	r(   r   rW   rZ   lstripreplaceossepr_   )r]   ry   rE   ra   r:   s       r<   rb   )Places365.load_file_list.<locals>.process   sK    JE99T__ell3.?.G.GRVV.TUWZ[^W___r>   )/)ri   r
   r_   _FILE_LIST_METAr(   r   rW   r'   rk   rl   rm   ziplist)
r:   r*   rb   rC   rq   rr   r]   imagesrU   r8   s
   `         r<   r6   Places365.load_file_list~   s    	`# 	`5c? 	` 	` ((4	yyD)$$T99  "$Z2023gdmF3  &\
tG}$$ 4 Zs   CC
)C
C
Cc                     U R                   U R                     u  p[        [        U R                  U5      U R
                  US9  g )Nrq   )_DEVKIT_METArN   r   r   	_BASE_URLr'   r:   rC   rq   s      r<   rl   Places365.download_devkit   s4    %%dll3	$WT^^T%BDIISVWr>   c                    [         R                  " U R                  5      (       a  g U R                  U R                  U R
                  4   u  p[        [        U R                  U5      U R                  US9  U R                  R                  S5      (       a?  [        R                  " U R                  R                  SS5      S   U R                  5        g g )Nr   rS   rU   r   r   )r   existsrZ   _IMAGES_METAr(   r)   r   r   r   r'   rV   rx   renamersplitr   s      r<   r9   Places365.download_images   s    ;;t''%%tzz4::&>?	$WT^^T%BDIISVW::  ))IIdoo,,S!4Q7I *r>   c                 X    SR                  S5      R                  " S0 U R                  D6$ )N
)zSplit: {split}zSmall: {small}re   )rW   format__dict__rJ   s    r<   
extra_reprPlaces365.extra_repr   s$    yy=>EEVVVr>   c                 0    [        USU R                  5      $ )Nr(   )r   _SPLITS)r:   r(   s     r<   r2   Places365._verify_split   s    eWdll;;r>   rC   rq   c                 R    [        XS9nU(       d  U(       d  [        SU S35      eU$ )Nr   z	The file zJ does not exist or is corrupted. You can set download=True to download it.)r   RuntimeError)r:   rC   rq   r*   	integritys        r<   rk   Places365._check_integrity   s3    #D2	D6!kl  r>   )r5   r4   r7   r-   r)   r(   r8   )T)r.   N)&__name__
__module____qualname____firstlineno____doc__r   r   r   rj   r|   r   r   r   ri   r   boolr	   r   r   r1   r_   r
   rF   rK   propertyrN   rZ   r   r   r3   r6   rl   r9   r   r2   rk   __static_attributes____classcell__)r;   s   @r<   r   r      s   4 ;G=I \]L
 X _`HO $m$nM"i#kJL &(,/3'5#CI# # 	#
 # H%# #8,# #$# 
# #, sCx   H H H )C ) )9 9d3icSVh>W8X 9%t %uT%S/=RTXY\T]=]7^ % XJWC W<3 <3 <S s d t  r>   r   )rx   r   pathlibr   typingr   r   r   r   r	   r
   r   urllib.parser   folderr   utilsr   r   r   visionr   r   re   r>   r<   <module>r      s4    	   D D D   " P P !\ \r>   