Ë
    þÍ:j^"  ã                   óŒ   — d dl Z d dlZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 ddlmZmZ ddlmZ  G d„ d	e«      Z G d
„ de«      Zy)é    N)ÚPath)ÚAnyÚCallableÚOptionalÚUnion)ÚImageé   )Údownload_and_extract_archiveÚverify_str_arg)ÚVisionDatasetc                   ó²   ‡ — e Zd ZdZ	 	 	 	 ddeeef   deee   ef   dee	   dee	   de
ddfˆ fd	„Zd
edeeef   fd„Zde
fd„Zdefd„Zdd„Zdefd„Zˆ xZS )Ú
Caltech101a?  `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         ‰| �  t        j                  j	                  |d«      ||¬«       t        j
                  | j                  d¬«       t        |t        «      r|g}|D �cg c]  }t        |dd«      ‘Œ c}| _
        |r| j                  «        | j                  «       st        d«      ‚t        t        j                  t        j                  j	                  | j                  d«      «      «      | _        | j                   j#                  d	«       d
ddddœŠ
t%        t'        ˆ
fd„| j                   «      «      | _        g | _        g | _        t/        | j                   «      D ]“  \  }}t1        t        j                  t        j                  j	                  | j                  d|«      «      «      }	| j*                  j3                  t5        d|	dz   «      «       | j,                  j3                  |	|gz  «       Œ• y c c}w )NÚ
caltech101©r   r   T©Úexist_okr   )ÚcategoryÚ
annotationúHDataset 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                 ó   •— | ‰v r‰|    S | S ©N© )ÚxÚname_maps    €úq/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchvision/datasets/caltech.pyú<lambda>z%Caltech101.__init__.<locals>.<lambda>H   s   ø€ ÀqÈHÁ}¸À¹€ ÐZ[€ ó    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,   r0   zCaltech101.__init__(   sˆ  ù€ ô 	‰ÑœŸ™Ÿ™ d¨LÓ9ÀYÐaqÐÔrÜ
�‰�D—I‘I¨Õ-Ü�k¤3Ô'Ø&˜-ˆKØbmÖnÐ]^œN¨1¨mÐ=WÕXÒnˆÔáØ�M‰MŒOà×$Ñ$Ô&ÜÐiÓjÐjä ¤§¡¬B¯G©G¯L©L¸¿¹ÐDZÓ,[Ó!\Ó]ˆŒØ�‰×ÑÐ2Ô3ð Ø#Ø)Ø+ñ	
ˆô &*¬#Ó.[Ð]a×]lÑ]lÓ*mÓ%nˆÔ"à "ˆŒ
ØˆŒÜ˜dŸo™oÓ.ò 	#‰DˆAˆqÜ”B—J‘JœrŸw™wŸ|™|¨D¯I©IÐ7MÈqÓQÓRÓSˆAØ�J‰J×Ñœe A q¨1¡u›oÔ.Ø�F‰F�M‰M˜!˜q˜c™'Õ"ñ	#ùò1 os   Á+Hr@   c                 ó  — ddl }t        j                  t        j                  j                  | j                  d| j                  | j                  |      d| j                  |   d›d�«      «      }g }| j                  D ]±  }|dk(  r|j                  | j                  |   «       Œ'|dk(  sŒ-|j                  j                  t        j                  j                  | j                  d	| j                  | j                  |      d
| j                  |   d›d�«      «      }|j                  |d   «       Œ³ t        |«      dkD  rt!        |«      n|d   }| j"                  �| j#                  |«      }| j$                  �| j%                  |«      }||fS )zž
        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   Úopenr1   r2   r3   r   r;   rA   r@   r   ÚappendÚioÚloadmatr?   rC   Útupler   r   )rF   r@   ÚscipyÚimgÚtargetrG   Údatas          r,   Ú__getitem__zCaltech101.__getitem__Q   sb  € ó 	ä�j‰jÜ�G‰G�L‰LØ—	‘	Ø&Ø—‘ §¡ u¡Ñ.Ø˜Ÿ™ EÑ*¨3Ð/¨tÐ4ó	ó
ˆð ˆØ×!Ñ!ò 	3ˆAØ�JŠØ—‘˜dŸf™f U™mÕ,Ø�lÓ"Ø—x‘x×'Ñ'Ü—G‘G—L‘LØŸ	™	Ø%Ø×2Ñ2°4·6±6¸%±=ÑAØ% d§j¡j°Ñ&7¸Ð%<¸DÐAó	ó�ð —‘˜d =Ñ1Õ2ð	3ô #& f£+°¢/”�v”°v¸a±yˆà�>‰>Ð%Ø—.‘. Ó%ˆCà× Ñ Ð,Ø×*Ñ*¨6Ó2ˆFà�Fˆ{Ðr.   c                 ó�   — t         j                  j                  t         j                  j                  | j                  d«      «      S )Nr   ©r1   r2   Úexistsr3   r   ©rF   s    r,   r7   zCaltech101._check_integrity|   ó)   € ä�w‰w�~‰~œbŸg™gŸl™l¨4¯9©9Ð6LÓMÓNÐNr.   c                 ó,   — t        | j                  «      S r(   ©rC   r@   ra   s    r,   Ú__len__zCaltech101.__len__€   ó   € Ü�4—:‘:‹Ðr.   c                 óŠ   — | j                  «       ry t        d| j                  dd¬«       t        d| j                  dd¬«       y )NzAhttps://drive.google.com/file/d/137RyRjvTBkBiIfeYBNZBtViDHQ6_Ewspz101_ObjectCategories.tar.gzÚ b224c7392d521a49829488ab0f1120d9©ÚfilenameÚmd5zAhttps://drive.google.com/file/d/175kQy3UsZ0wUEHZjqkUDdNVssr7bgh_mzAnnotations.tarÚ 6f83eeb1f24d99cab4eb377263132c91©r7   r
   r   ra   s    r,   r   zCaltech101.downloadƒ   sC   € Ø× Ñ Ô"Øä$ØOØ�I‰IØ2Ø2õ		
ô 	%ØOØ�I‰IØ&Ø2ö		
r.   c                 ó:   —  dj                   di | j                  ¤ŽS )NzTarget type: {target_type}r)   )ÚformatÚ__dict__ra   s    r,   Ú
extra_reprzCaltech101.extra_repr”   s   € Ø2Ð+×2Ñ2ÑC°T·]±]ÑCÐCr.   )r   NNF©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r6   r   r=   r   r   Úboolr0   ÚintrX   r   r]   r7   re   r   rq   Ú__classcell__©rK   s   @r,   r   r      s¿   ø„ ñð< .8Ø(,Ø/3Øñ'#à�C˜�IÑð'#ð ˜4 ™9 c˜>Ñ*ð'#ð ˜HÑ%ð	'#ð
 # 8Ñ,ð'#ð ð'#ð 
õ'#ðR) ð )¨¨s°C¨x©ó )ðVO $ó Oð˜ó ó
ð"D˜C÷ Dr.   r   c                   ó†   ‡ — e Zd ZdZ	 	 	 ddedee   dee   deddf
ˆ fd„Zd	e	de
eef   fd
„Zdefd„Zde	fd„Zdd„Zˆ xZS )Ú
Caltech256aÞ  `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         ‰	| �  t        j                  j	                  |d«      ||¬«       t        j
                  | j                  d¬«       |r| j                  «        | j                  «       st        d«      ‚t        t        j                  t        j                  j	                  | j                  d«      «      «      | _        g | _        g | _        t        | j                  «      D ]²  \  }}t!        t        j                  t        j                  j	                  | j                  d|«      «      D �cg c]  }|j#                  d«      r|‘Œ c}«      }| j                  j%                  t'        d|dz   «      «       | j                  j%                  ||gz  «       Œ´ y c c}w )	NÚ
caltech256r   Tr   r   Ú256_ObjectCategoriesrO   r	   )r/   r0   r1   r2   r3   r4   r   r   r7   r8   r9   r:   r;   r@   rA   rB   rC   ÚendswithrD   rE   )
rF   r   r   r   r   rH   rI   ÚitemrJ   rK   s
            €r,   r0   zCaltech256.__init__§   s9  ø€ ô 	‰ÑœŸ™Ÿ™ d¨LÓ9ÀYÐaqÐÔrÜ
�‰�D—I‘I¨Õ-áØ�M‰MŒOà×$Ñ$Ô&ÜÐiÓjÐjä ¤§¡¬B¯G©G¯L©L¸¿¹ÐDZÓ,[Ó!\Ó]ˆŒØ "ˆŒ
ØˆŒÜ˜dŸo™oÓ.ò 		#‰DˆAˆqÜô !#§
¡
¬2¯7©7¯<©<¸¿	¹	ÐCYÐ[\Ó+]Ó ^öàØ—}‘} VÔ,ò òóˆAð �J‰J×Ñœe A q¨1¡u›oÔ.Ø�F‰F�M‰M˜!˜q˜c™'Õ"ñ		#ùòs   Ä9F$
r@   c                 ó˜  — t        j                  t        j                  j	                  | j
                  d| j                  | j                  |      | j                  |   dz   d›d| j                  |   d›d�«      «      }| j                  |   }| j                  �| j                  |«      }| j                  �| j                  |«      }||fS )z–
        Args:
            index (int): Index

        Returns:
            tuple: (image, target) where target is index of the target class.
        r   r	   Ú03dÚ_rN   rO   )r   rT   r1   r2   r3   r   r;   rA   r@   r   r   )rF   r@   rZ   r[   s       r,   r]   zCaltech256.__getitem__Å   s¹   € ô �j‰jÜ�G‰G�L‰LØ—	‘	Ø&Ø—‘ §¡ u¡Ñ.Ø—6‘6˜%‘= 1Ñ$ SÐ)¨¨4¯:©:°eÑ+<¸SÐ*AÀÐFó	ó
ˆð —‘˜‘ˆà�>‰>Ð%Ø—.‘. Ó%ˆCà× Ñ Ð,Ø×*Ñ*¨6Ó2ˆFà�Fˆ{Ðr.   c                 ó�   — t         j                  j                  t         j                  j                  | j                  d«      «      S )Nr   r_   ra   s    r,   r7   zCaltech256._check_integrityà   rb   r.   c                 ó,   — t        | j                  «      S r(   rd   ra   s    r,   re   zCaltech256.__len__ä   rf   r.   c                 óX   — | j                  «       ry t        d| j                  dd¬«       y )NzAhttps://drive.google.com/file/d/1r6o0pSROcV1_VwT4oSjA2FBUSCWGuxLKz256_ObjectCategories.tarÚ 67b4f42ca05d46448c6bb8ecd2220f6dri   rm   ra   s    r,   r   zCaltech256.downloadç   s)   € Ø× Ñ Ô"Øä$ØOØ�I‰IØ/Ø2ö		
r.   )NNFrr   )rs   rt   ru   rv   r6   r   r   rw   r0   rx   rX   r   r]   r7   re   r   ry   rz   s   @r,   r|   r|   ˜   sŒ   ø„ ñð" )-Ø/3Øñ#àð#ð ˜HÑ%ð#ð # 8Ñ,ð	#ð
 ð#ð 
õ#ð< ð ¨¨s°C¨x©ó ð6O $ó Oð˜ó ÷	
r.   r|   )r1   Úos.pathÚpathlibr   Útypingr   r   r   r   ÚPILr   Úutilsr
   r   Úvisionr   r   r|   r)   r.   r,   ú<module>r�      s<   ðÛ 	Û Ý ß 1Ó 1å ç ?Ý !ôID�ô IDôXX
�õ X
r.   