
    ڧg
                     j    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dS )	    )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 8ca2778205c41d23104230ba66911c7aNFroot	transformtarget_transformdownloadreturnc           
          t                                          |||           t           j                  dz   _        |r                                                                   st          d          t           j        dz            5 }d |D              _	        d d d            n# 1 swxY w Y   t          t           j	        t          t           j	                                                 _        t           j                            d                     _         fd j        D              _        d S )N)r   r   r   z;Dataset not found. You can use download=True to download itzClassName.txtc                 F    g | ]}|d d                                          S )   N)strip).0cs     W/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/datasets/sun397.py
<listcomp>z#SUN397.__init__.<locals>.<listcomp>.   s(    555aAabbEKKMM555    z	sun_*.jpgc                     g | ]G}j         d                     |                    j                  j        dd                            HS )/r	   )class_to_idxjoinrelative_to	_data_dirparts)r   pathselfs     r   r   z#SUN397.__init__.<locals>.<listcomp>3   sW     
 
 
Z^Dchht'7'7'G'G'MaPRd'STTU
 
 
r   )super__init__r   r   r#   	_download_check_existsRuntimeErroropenclassesdictziprangelenr    listrglob_image_files_labels)r&   r   r   r   r   f	__class__s   `     r   r(   zSUN397.__init__   ss    	EUVVVdi83 	NN!!## 	^\]]]$.?233 	6q551555DL	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 !T\5T\9J9J3K3K!L!LMM !5!5k!B!BCC
 
 
 
bfbs
 
 
s   B11B58B5c                 *    t          | j                  S N)r1   r4   r&   s    r   __len__zSUN397.__len__7   s    4$%%%r   idxc                    | j         |         | j        |         }}t          j                            |                              d          }| j        r|                     |          }| j        r|                     |          }||fS )NRGB)r4   r5   PILImager,   convertr   r   )r&   r<   
image_filelabelimages        r   __getitem__zSUN397.__getitem__:   s~     -c2DL4EE
	z**22599> 	*NN5))E  	1))%00Ee|r   c                 4    | j                                         S r9   )r#   is_dirr:   s    r   r*   zSUN397._check_existsF   s    ~$$&&&r   c                 t    |                                  rd S t          | j        | j        | j                   d S )N)download_rootmd5)r*   r
   _DATASET_URLr   _DATASET_MD5r:   s    r   r)   zSUN397._downloadI   s?     	F$T%6diUYUfggggggr   )NNF)r   N)__name__
__module____qualname____doc__rK   rL   r   strr   r   r   boolr(   intr;   r   r   rE   r*   r)   __classcell__)r7   s   @r   r   r   
   s#         QL5L
 )-/3
 
CI
 H%
 #8,	

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