
    Ph                         d dl Z d dl mZ d dl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
e      Zy)    N)path)AnyCallableDictListOptionalTuple)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ZdddddddZ	ddddde
fde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f      ee   f   fd$Zd-d%Zd-d&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 ).	Places365a  `Places365 <http://places2.csail.mit.edu/index.html>`_ classification dataset.

    Args:
        root (string): 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 an 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         |   |||       | 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	           iC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torchvision/datasets/places365.pyr.   zPlaces365.__init__?   s     	EUV''.

*.*>*>x*H'd'"&"5"5h"?	4<  "     indexc                     | j                   |   \  }}| j                  |      }| j                  | j                  ||      \  }}||fS N)r4   r*   
transforms)r7   r;   filetargetimages        r9   __getitem__zPlaces365.__getitem__U   sJ    yy'fD!??& OOE6:ME6f}r:   c                 ,    t        | j                        S r=   )lenr4   r7   s    r9   __len__zPlaces365.__len__^   s    499~r:   c                 &    d| j                   v rdS dS )Nr   r   )r%   rE   s    r9   variantzPlaces365.varianta   s    )TZZ7{GZ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%   
startswithrH   r   joinr$   )r7   sizedirs      r9   
images_dirzPlaces365.images_dire   s`    

u::  )$q/CZZL$(Cyy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 r=   )r%   int)rU   clsidxs      r9   processz*Places365.load_categories.<locals>.processo   s    zz|HCC= r:   c              3   .   K   | ]  } |        y wr=    ).0rU   rZ   s     r9   	<genexpr>z,Places365.load_categories.<locals>.<genexpr>y   s     ="$"s   )strr	   rW   _CATEGORIES_METAr   rP   r$   _check_integritydownload_devkitopendictsortedkeys)r7   r'   r?   md5fhr2   rZ   s         @r9   r0   zPlaces365.load_categoriesn   s    	!# 	!%S/ 	! ))	cyyD)$$T39  "$Z2="==L  l'')*L88 Zs   <B44B=c                     ddt         dt        t         t        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)NrU   r+   c                     | j                         \  }}t        j                  j                  |j	                  |      j                  |t        j                              t        |      fS r=   )	r%   r   rP   rS   lstripreplaceosseprW   )rU   rn   rA   rY   r7   s       r9   rZ   z)Places365.load_file_list.<locals>.process~   sM    JE399T__ell3.?.G.GRVV.TUWZ[^W___r:   )/)r_   r	   rW   _FILE_LIST_METAr%   r   rP   r$   ra   rb   rc   ziplist)
r7   r'   rZ   r?   rg   rh   rU   imagesrN   r5   s
   `         r9   r3   zPlaces365.load_file_list}   s    	`# 	`5c? 	` ((4	cyyD)$$T39  "$Z2023gdmF3  &\
7tG}$$ 4 Zs   CC CCCc                     | j                   | j                     \  }}t        t        | j                  |      | j
                  |       y )Nrg   )_DEVKIT_METArH   r   r
   	_BASE_URLr$   r7   r?   rg   s      r9   rb   zPlaces365.download_devkit   s6    %%dll3	c$WT^^T%BDIISVWr:   c                    t        j                  | j                        rt        d| j                   d      | j                  | j
                  | j                  f   \  }}t        t        | j                  |      | j                  |       | j
                  j                  d      r>t        j                  | j                  j                  dd      d   | j                         y y )NzThe directory z[ already exists. If you want to re-download or re-extract the images, delete the directory.ru   rL   rN   r   r   )r   existsrS   RuntimeError_IMAGES_METAr%   r&   r   r
   rw   r$   rO   rm   renamersplitrx   s      r9   r6   zPlaces365.download_images   s    ;;t'  1 2( ) 
 %%tzz4::&>?	c$WT^^T%BDIISVW::  )IIdoo,,S!4Q7I *r:   c                 X     dj                  d      j                  di | j                  S )N
)zSplit: {split}zSmall: {small}r\   )rP   format__dict__rE   s    r9   
extra_reprzPlaces365.extra_repr   s&    Etyy=>EEVVVr:   c                 0    t        |d| j                        S )Nr%   )r   _SPLITS)r7   r%   s     r9   r/   zPlaces365._verify_split   s    eWdll;;r:   r?   rg   c                 F    t        ||      }|s|st        d| d      |S )Nru   z	The file zJ does not exist or is corrupted. You can set download=True to download it.)r   r{   )r7   r?   rg   r'   	integritys        r9   ra   zPlaces365._check_integrity   s5    #Dc2	D6!kl  r:   )T)r+   N)"__name__
__module____qualname____doc__r   rw   rv   r`   rp   r|   r   r_   boolr   r   r   r.   rW   r	   rB   rF   propertyrH   rS   r   r   r0   r3   rb   r6   r   r/   ra   __classcell__)r8   s   @r9   r   r      s   4 ;G=I \]L
 X _`HO $m$nM"i#kJL &(,/3'5## # 	#
 # 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   )rm   r   typingr   r   r   r   r   r	   urllib.parser
   folderr   utilsr   r   r   visionr   r   r\   r:   r9   <module>r      s.    	  = =   " P P !_ _r:   