ó
    Eñiá"  ã                   ó˜   • 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Ú
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                 ó   >• U T;   a  TU    $ U $ ©N© )ÚxÚname_maps    €ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/caltech.pyÚ<lambda>Ú%Caltech101.__init__.<locals>.<lambda>I   s   ø€ ÀqÈHÃ}¸À¹Ð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ˆ  ù€ ô 	‰ÑœŸ™Ÿ™ d¨LÓ9ÀYÐÑrÜ
�Š�D—I‘I¨Ò-Ü�k¤3×'Ñ'Ø&˜-ˆKÙbmÓnÒbmÐ]^œN¨1¨mÐ=WÖXÑbmÑ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Ü”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˜!˜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[  € ó 	ä�jŠjÜ�G‰G�L‰LØ—	‘	Ø&Ø—‘ §¡ u¡Ñ.Ø˜Ÿ™ EÑ*¨3Ð/¨tÐ4ó	ó
ˆð ˆØ×!Ô!ˆ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ñ "ô #& f£+°£/”�v”°v¸a±yˆà�>‰>Ñ%Ø—.‘. Ó%ˆCà× Ñ Ñ,Ø×*Ñ*¨6Ó2ˆFàˆ{Ðr1   c                 ó�   • [         R                  R                  [         R                  R                  U R                  S5      5      $ )Nr   ©r4   r5   Úexistsr6   r   ©rI   s    r.   r:   ÚCaltech101._check_integrity}   ó)   € ä�w‰w�~‰~œbŸg™gŸl™l¨4¯9©9Ð6LÓ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ò		
ô —g‘g—l‘l 4§9¡9¨mÓ<ˆÜŸš KÖ0ˆIØ×!Ñ! %×(Ó(Ü¤§¡§¡¨[Ó DÀdÇiÁiÖPñ 1ô 	�Š�kÔ"Ü
�	Š	”"—'‘'—,‘,˜tŸy™yÐ*;Ó<Õ=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ÑC°T·]±]Ñ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 ™9 c˜>Ñ*ð'#ð ˜HÑ%ð	'#ð
 # 8Ñ,ð'#ð ð'#ð 
÷'#ð '#ðR) ð )¨¨s°C¨x©ô )ð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  ø€ ô 	‰ÑœŸ™Ÿ™ d¨LÓ9ÀYÐÑrÜ
�Š�D—I‘I¨Ò-æØ�M‰MŒOà×$Ñ$×&Ñ&ÜÐiÓjÐjä ¤§¢¬B¯G©G¯L©L¸¿¹ÐDZÓ,[Ó!\Ó]ˆŒØ "ˆŒ
ØˆŒÜ˜dŸo™oÖ.‰DˆAÜô !#§
¢
¬2¯7©7¯<©<¸¿	¹	ÐCYÐ[\Ó+]Ô ^óâ ^˜Ø—}‘} V×,÷ Ù ^ñóˆAð �J‰J×Ñœe A q¨1¡u›oÔ.Ø�F‰F�M‰M˜!˜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·   € ô �jŠjÜ�G‰G�L‰LØ—	‘	Ø&Ø—‘ §¡ u¡Ñ.Ø—6‘6˜%‘= 1Ñ$ SÐ)¨¨4¯:©:°eÑ+<¸SÐ*AÀÐFó	ó
ˆð —‘˜‘ˆà�>‰>Ñ%Ø—.‘. Ó%ˆCà× Ñ Ñ,Ø×*Ñ*¨6Ó2ˆFàˆ{Ð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Ø�I‰IØ/Ø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Ñ,ð	#ð
 ð#ð 
÷#ð #ð< ð ¨¨s°C¨x©ô ð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   