
    kho                     f    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  G d de      Zy	)
    )Path)AnyCallableOptionalTupleUnion   )default_loader)download_and_extract_archive)VisionDatasetc                        e Zd ZdZdZdZdddefdeee	f   de
e   de
e   d	ed
eeee	f   gef   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 )SUN397a4  `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 or torch.Tensor, depends on the given loader,
            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.
        loader (callable, optional): A function to load an image given its path.
            By default, it uses PIL as its image loader, but users could also pass in
            ``torchvision.io.decode_image`` for decoding image data into tensors directly.
    z;http://vision.princeton.edu/projects/2010/SUN/SUN397.tar.gz 8ca2778205c41d23104230ba66911c7aNFroot	transformtarget_transformdownloadloader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_labelsr   )
selfr   r   r   r   r   fcpath	__class__s
            W/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/datasets/sun397.pyr   zSUN397.__init__    sA    	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E<;E7E<AF7E<<Fc                 ,    t        | j                        S N)r&   r*   r/   s    r4   __len__zSUN397.__len__<   s    4$$%%    idxc                     | j                   |   | j                  |   }}| j                  |      }| j                  r| j                  |      }| j                  r| j	                  |      }||fS r6   )r*   r.   r   r   r   )r/   r:   
image_filelabelimages        r4   __getitem__zSUN397.__getitem__?   se     --c2DLL4EE
J'>>NN5)E  ))%0Ee|r9   c                 6    | j                   j                         S r6   )r   is_dirr7   s    r4   r   zSUN397._check_existsK   s    ~~$$&&r9   c                 ~    | j                         ry t        | j                  | j                  | j                         y )N)download_rootmd5)r   r   _DATASET_URLr   _DATASET_MD5r7   s    r4   r   zSUN397._downloadN   s.    $T%6%6diiUYUfUfgr9   )r   N)__name__
__module____qualname____doc__rE   rF   r
   r   strr   r   r   boolr   r   intr8   r   r?   r   r   __classcell__)r3   s   @r4   r   r   
   s    $ QL5L
 )-/34BCI H% #8,	
  %T	*+S01 
8& &
s 
uS#X 
't 'hr9   r   N)pathlibr   typingr   r   r   r   r   folderr
   utilsr   visionr   r    r9   r4   <module>rU      s'     8 8 " / !Gh] Ghr9   