
    9i"                         S SK r S SK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 " S
 S\5      rg)    N)Path)AnyCallableOptionalUnion)Image   )download_and_extract_archiveextract_archiveverify_str_arg)VisionDatasetc                      ^  \ rS rSrSr    SS\\\4   S\\\   \4   S\	\
   S\	\
   S\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	\4S jrSrU =r$ )
Caltech101   a  `Caltech 101 <https://data.caltech.edu/records/20086>`_ Dataset.

.. warning::

    This class needs `scipy <https://docs.scipy.org/doc/>`_ to load target files from `.mat` format.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory
        ``caltech101`` exists or will be saved to if download is set to True.
    target_type (string or list, optional): Type of target to use, ``category`` or
        ``annotation``. Can also be a list to output a tuple with all specified
        target types.  ``category`` represents the target class, and
        ``annotation`` is a list of points from a hand-generated outline.
        Defaults to ``category``.
    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.

        .. warning::

            To download the dataset `gdown <https://github.com/wkentaro/gdown>`_ is required.
Nroottarget_type	transformtarget_transformdownloadreturnc           
      ,  >^
 [         TU ]  [        R                  R	                  US5      X4S9  [        R
                  " U R                  SS9  [        U[        5      (       a  U/nU Vs/ s H  n[        USS5      PM     snU l
        U(       a  U R                  5         U R                  5       (       d  [        S5      e[        [        R                  " [        R                  R	                  U R                  S5      5      5      U l        U R                   R#                  S	5        S
SSSS.m
[%        ['        U
4S jU R                   5      5      U l        / U l        / U l        [/        U R                   5       H  u  px[1        [        R                  " [        R                  R	                  U R                  SU5      5      5      n	U R*                  R3                  [5        SU	S-   5      5        U R,                  R3                  X/-  5        M     g s  snf )N
caltech101r   r   Texist_okr   )category
annotationHDataset not found or corrupted. You can use download=True to download it101_ObjectCategoriesBACKGROUND_GoogleFaces_2Faces_3Motorbikes_16Airplanes_Side_2)Faces
Faces_easy
Motorbikes	airplanesc                    > U T;   a  TU    $ U $ N )xname_maps    \/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torchvision/datasets/caltech.py<lambda>%Caltech101.__init__.<locals>.<lambda>I   s    qH}8[Z[8[    r	   )super__init__ospathjoinmakedirsr   
isinstancestrr   r   r   _check_integrityRuntimeErrorsortedlistdir
categoriesremovelistmapannotation_categoriesindexy	enumeratelenextendrange)selfr   r   r   r   r   ticnr-   	__class__s             @r.   r3   Caltech101.__init__)   s    	dL9Yr
DII-k3''&-Kbmnbm]^N1m=WXbmnMMO$$&&ijj BGGLLDZ,[!\]23 #)+	
 &*#.[]a]l]l*m%n" "
doo.DABJJrww||DII7MqQRSAJJeAq1uo.FFMM!c'" /1 os   *HrC   c                 .   SSK n[        R                  " [        R                  R                  U R                  SU R                  U R                  U      SU R                  U   S S35      5      n/ nU R                   H  nUS:X  a   UR                  U R                  U   5        M)  US:X  d  M1  UR                  R                  [        R                  R                  U R                  S	U R                  U R                  U      S
U R                  U   S S35      5      nUR                  US   5        M     [        U5      S:  a  [!        U5      OUS   nU R"                  b  U R#                  U5      nU R$                  b  U R%                  U5      nX44$ )zv
Args:
    index (int): Index

Returns:
    tuple: (image, target) where the type of target specified by target_type.
r   Nr   image_04d.jpgr   r   Annotationsannotation_z.matobj_contourr	   )scipy.ior   openr4   r5   r6   r   r>   rD   rC   r   appendioloadmatrB   rF   tupler   r   )rI   rC   scipyimgtargetrJ   datas          r.   __getitem__Caltech101.__getitem__R   s[    	jjGGLL		&u.E*3/t4	
 !!AJdffUm,l"xx''GGLL		%22466%=A%djj&7%<DA	 d=12 " #&f+/vvay>>%..%C  ,**62F{r1   c                     [         R                  R                  [         R                  R                  U R                  S5      5      $ )Nr   r4   r5   existsr6   r   rI   s    r.   r:   Caltech101._check_integrity}   )    ww~~bggll4996LMNNr1   c                 ,    [        U R                  5      $ r*   rF   rC   rf   s    r.   __len__Caltech101.__len__       4::r1   c                 (   U R                  5       (       a  g [        SU R                  SSS9  [        R                  R                  U R                  S5      n[        R                  " U5       HN  nUR                  S5      (       d  M  [        [        R                  R                  X5      U R                  5        MP     [        R                  " U5        [        R                  " [        R                  R                  U R                  S5      5        g )NzBhttps://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zipzcaltech-101.zip 3138e1922a9193bfa496528edbbc45d0)download_rootfilenamemd5zcaltech-101z.gz)r:   r
   r   r4   r5   r6   r=   endswithr   shutilrmtreer?   )rI   gzip_folder	gzip_files      r.   r   Caltech101.download   s      ""$P))&2		
 ggll499m<K0I!!%(([ DdiiP 1 	k"
		"'',,tyy*;<=r1   c                 :    SR                   " S0 U R                  D6$ )NzTarget type: {target_type}r+   )format__dict__rf   s    r.   
extra_reprCaltech101.extra_repr   s    +22CT]]CCr1   )rB   r>   rC   r   rD   )r   NNFr   N)__name__
__module____qualname____firstlineno____doc__r   r9   r   r@   r   r   boolr3   intr\   r   ra   r:   rk   r   r|   __static_attributes____classcell__rN   s   @r.   r   r      s    < .8(,/3'#CI'# 49c>*'# H%	'#
 #8,'# '# 
'# '#R) )sCx )VO$ O >"DC D Dr1   r   c                      ^  \ rS rSrSr   SS\S\\   S\\   S\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$ )
Caltech256   a  `Caltech 256 <https://data.caltech.edu/records/20087>`_ Dataset.

Args:
    root (str or ``pathlib.Path``): Root directory of dataset where directory
        ``caltech256`` exists or will be saved to if download is set to True.
    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.
Nr   r   r   r   r   c           
      r  > [         T	U ]  [        R                  R	                  US5      X#S9  [        R
                  " U R                  SS9  U(       a  U R                  5         U R                  5       (       d  [        S5      e[        [        R                  " [        R                  R	                  U R                  S5      5      5      U l        / U l        / U l        [        U R                  5       H  u  pV[!        [        R                  " [        R                  R	                  U R                  SU5      5       Vs/ s H  nUR#                  S5      (       d  M  UPM     sn5      nU R                  R%                  ['        SUS-   5      5        U R                  R%                  X/-  5        M     g s  snf )	N
caltech256r   Tr   r   256_ObjectCategoriesrS   r	   )r2   r3   r4   r5   r6   r7   r   r   r:   r;   r<   r=   r>   rC   rD   rE   rF   rs   rG   rH   )
rI   r   r   r   r   rK   rL   itemrM   rN   s
            r.   r3   Caltech256.__init__   s5    	dL9Yr
DII-MMO$$&&ijj BGGLLDZ,[!\] "
doo.DA !#

277<<		CY[\+] ^ ^}}V,  ^A JJeAq1uo.FFMM!c'" /s   >F4
F4
rC   c                    [         R                  " [        R                  R	                  U R
                  SU R                  U R                  U      U R                  U   S-   S SU R                  U   S S35      5      nU R                  U   nU R                  b  U R                  U5      nU R                  b  U R                  U5      nX#4$ )zn
Args:
    index (int): Index

Returns:
    tuple: (image, target) where target is index of the target class.
r   r	   03d_rR   rS   )r   rX   r4   r5   r6   r   r>   rD   rC   r   r   )rI   rC   r^   r_   s       r.   ra   Caltech256.__getitem__   s     jjGGLL		&u.66%=1$S)4::e+<S*AF	
 >>%..%C  ,**62F{r1   c                     [         R                  R                  [         R                  R                  U R                  S5      5      $ )Nr   rd   rf   s    r.   r:   Caltech256._check_integrity   rh   r1   c                 ,    [        U R                  5      $ r*   rj   rf   s    r.   rk   Caltech256.__len__   rm   r1   c                 \    U R                  5       (       a  g [        SU R                  SSS9  g )NzKhttps://data.caltech.edu/records/nyy15-4j048/files/256_ObjectCategories.tarz256_ObjectCategories.tar 67b4f42ca05d46448c6bb8ecd2220f6d)rq   rr   )r:   r
   r   rf   s    r.   r   Caltech256.download   s,      ""$YII/2		
r1   )r>   rC   rD   )NNFr~   )r   r   r   r   r   r9   r   r   r   r3   r   r\   r   ra   r:   rk   r   r   r   r   s   @r.   r   r      s    " )-/3## H%# #8,	#
 # 
# #< sCx 6O$ O 	
 	
r1   r   )r4   os.pathrt   pathlibr   typingr   r   r   r   PILr   utilsr
   r   r   visionr   r   r   r+   r1   r.   <module>r      sB    	    1 1  P P !ID IDXX
 X
r1   