
    ,}h
                     b    d dl mZ d dlmZmZmZmZmZ d dlZ	ddl
mZ ddlmZ  G d de      Zy)	    )Path)AnyCallableOptionalTupleUnionN   )download_and_extract_archive)VisionDatasetc                        e Zd ZdZdZdZ	 	 	 ddeeef   de	e
   de	e
   ded	df
 fd
Zd	efdZded	eeef   fdZd	efdZddZ xZS )SUN397a  `The SUN397 Data Set <https://vision.princeton.edu/projects/2010/SUN/>`_.

    The SUN397 or Scene UNderstanding (SUN) is a dataset for scene recognition consisting of
    397 categories with 108'754 images.

    Args:
        root (str or ``pathlib.Path``): Root directory of the dataset.
        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.
        download (bool, optional): If true, downloads the dataset from the internet and
            puts it in root directory. If dataset is already downloaded, it is not
            downloaded again.
    z;http://vision.princeton.edu/projects/2010/SUN/SUN397.tar.gz 8ca2778205c41d23104230ba66911c7aNroot	transformtarget_transformdownloadreturnc           
         t         |   |||       t        | j                        dz  | _        |r| j                          | j                         st        d      t        | j                  dz        5 }|D cg c]  }|dd  j                          c}| _
        d d d        t        t        | j                  t        t        | j                                          | _        t!        | j                  j#                  d            | _        | j$                  D cg c]F  }| j                  dj'                  |j)                  | j                        j*                  dd	          H c}| _        y c c}w # 1 sw Y   xY wc c}w )
N)r   r   r   z;Dataset not found. You can use download=True to download itzClassName.txt   z	sun_*.jpg/r	   )super__init__r   r   	_data_dir	_download_check_existsRuntimeErroropenstripclassesdictziprangelenclass_to_idxlistrglob_image_filesjoinrelative_toparts_labels)	selfr   r   r   r   fcpath	__class__s	           Z/var/www/html/test/engine/venv/lib/python3.12/site-packages/torchvision/datasets/sun397.pyr   zSUN397.__init__   s8    	EUVdii83NN!!#\]]$..?23 	6q345aAabEKKM5DL	6 !T\\5T\\9J3K!LM !5!5k!BC cgbsbs
Z^Dchht'7'7'G'M'MaPR'STU
 6	6 	6
s%   6E5;E0E5AF0E55E>c                 ,    t        | j                        S N)r$   r(   r-   s    r2   __len__zSUN397.__len__7   s    4$$%%    idxc                    | j                   |   | j                  |   }}t        j                  j	                  |      j                  d      }| j                  r| j                  |      }| j                  r| j                  |      }||fS )NRGB)r(   r,   PILImager   convertr   r   )r-   r8   
image_filelabelimages        r2   __getitem__zSUN397.__getitem__:   st     --c2DLL4EE
		z*2259>>NN5)E  ))%0Ee|r7   c                 6    | j                   j                         S r4   )r   is_dirr5   s    r2   r   zSUN397._check_existsF   s    ~~$$&&r7   c                 ~    | j                         ry t        | j                  | j                  | j                         y )N)download_rootmd5)r   r
   _DATASET_URLr   _DATASET_MD5r5   s    r2   r   zSUN397._downloadI   s.    $T%6%6diiUYUfUfgr7   )NNF)r   N)__name__
__module____qualname____doc__rG   rH   r   strr   r   r   boolr   intr6   r   r   rA   r   r   __classcell__)r1   s   @r2   r   r   
   s     QL5L
 )-/3
CI
 H%
 #8,	

 
 

4& &
s 
uS#X 
't 'hr7   r   )pathlibr   typingr   r   r   r   r   	PIL.Imager;   utilsr
   visionr   r    r7   r2   <module>rW      s'     8 8  / !Bh] Bhr7   