
    hp                     r    S SK r S SKJr  S SKJrJrJr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)AnyCallableOptionalUnion   )default_loader)check_integritydownload_and_extract_archivedownload_url)VisionDatasetc                      ^  \ rS rSrSrSrSrSrSSS\4S\	\
\4   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rSS jrSrU =r$ )SBU   a  `SBU Captioned Photo <http://www.cs.virginia.edu/~vicente/sbucaptions/>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where tarball
        ``SBUCaptionedPhotoDataset.tar.gz`` exists.
    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.
zHhttps://www.cs.rice.edu/~vo9/sbucaptions/SBUCaptionedPhotoDataset.tar.gzzSBUCaptionedPhotoDataset.tar.gz 9aec147b3488753cf758b4d493422285NTroot	transformtarget_transformdownloadloaderreturnc                 >  > [         TU ]  XUS9  XPl        U(       a  U R                  5         U R	                  5       (       d  [        S5      e/ U l        / U l        [        R                  R                  U R                  SS5      n[        R                  R                  U R                  SS5      n[        [        U5      [        U5      5       H  u  pUR                  5       n
[        R                  R                  U
5      n[        R                  R                  U R                  SU5      n[        R                  R!                  U5      (       d  M  U	R                  5       nU R                  R#                  U5        U R                  R#                  U5        M     g )N)r   r   zHDataset not found or corrupted. You can use download=True to download itdataset$SBU_captioned_photo_dataset_urls.txtz(SBU_captioned_photo_dataset_captions.txt)super__init__r   r   _check_integrityRuntimeErrorphotoscaptionsospathjoinr   zipopenrstripbasenameexistsappend)selfr   r   r   r   r   file1file2line1line2urlphotofilenamecaption	__class__s                 P/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/datasets/sbu.pyr   SBU.__init__!   s     	EUVMMO$$&&ijj TYY	3YZTYY	3]^UT%[9LE,,.CGG$$S)Eww||DIIy%@Hww~~h'',,.""5)$$W- :    indexc                 0   [         R                  R                  U R                  SU R                  U   5      nU R                  U5      nU R                  b  U R                  U5      nU R                  U   nU R                  b  U R                  U5      nX44$ )zl
Args:
    index (int): Index

Returns:
    tuple: (image, target) where target is a caption for the photo.
r   )	r!   r"   r#   r   r   r   r   r    r   )r*   r7   r1   imgtargets        r4   __getitem__SBU.__getitem__B   s     77<<		9dkk%6HIkk(#>>%..%Cu%  ,**62F{r6   c                 ,    [        U R                  5      $ )z$The number of photos in the dataset.)lenr   )r*   s    r4   __len__SBU.__len__U   s    4;;r6   c                     U R                   n[        R                  R                  XR                  5      n[        X R                  5      (       d  gg)z1Check the md5 checksum of the downloaded tarball.FT)r   r!   r"   r#   r1   r
   md5_checksum)r*   r   fpaths      r4   r   SBU._check_integrityY   s8    yyT==1u&7&788r6   c           	         U R                  5       (       a  g[        U R                  U R                  U R                  U R                  U R
                  5        [        [        R                  R                  U R                  SS5      5       nU HH  nUR                  5       n [        U[        R                  R                  U R                  S5      5        MJ     SSS5        g! [         a     Mb  f = f! , (       d  f       g= f)zEDownload and extract the tarball, and download each individual photo.Nr   r   )r   r   r/   r   r1   rB   r%   r!   r"   r#   r&   r   OSError)r*   fhliner/   s       r4   r   SBU.downloada   s       ""$TXXtyy$))T]]TXTeTef "'',,tyy)5[\]ackkm bggll499i&HI  ^]
    ^]s0   C5#4C$C5$
C2.C51C22C55
D)r    r   r   )r   N)__name__
__module____qualname____firstlineno____doc__r/   r1   rB   r	   r   strr   r   r   boolr   r   inttupler;   r?   r   r   __static_attributes____classcell__)r3   s   @r4   r   r      s    " UC0H5L
 )-/3'5.CI. H%. #8,	.
 . #$. 
. .B sCx &   $  r6   r   )r!   pathlibr   typingr   r   r   r   folderr	   utilsr
   r   r   visionr   r    r6   r4   <module>r[      s+    	  1 1 " N N !g- gr6   