ó
    Eñi¹2  ã                   óâ  • S SK r S SKr S SKJr  S SKJrJrJrJrJ	r	  S SK
Jr  SSKJr  S\S\	\\\S	4   4   S
\4S jrS\S
\4S jrS\	\\4   S
\\\   \\\4   4   4S jr    SS\	\\4   S\\\\4      S\\	\\\S	4   4      S\\\/\4      S\S
\\\\4      4S jjr " S S\5      rSrS\	\\4   S
\R                  4S jrS\	\\4   S
\4S jrS\	\\4   S
\4S jr " S S\5      rg)é    N)ÚPath)ÚAnyÚCallableÚcastÚOptionalÚUnion)ÚImageé   )ÚVisionDatasetÚfilenameÚ
extensions.Úreturnc                 óˆ   • U R                  5       R                  [        U[        5      (       a  U5      $ [	        U5      5      $ )zèChecks if a file is an allowed extension.

Args:
    filename (string): path to a file
    extensions (tuple of strings): extensions to consider (lowercase)

Returns:
    bool: True if the filename ends with one of given extensions
)ÚlowerÚendswithÚ
isinstanceÚstrÚtuple)r   r   s     ÚX/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/datasets/folder.pyÚhas_file_allowed_extensionr      s7   € ð �>‰>Ó×$Ñ$´:¸jÌ#×3NÑ3N ZÓfÐfÔTYÐZdÓTeÓfÐfó    c                 ó"   • [        U [        5      $ )z¨Checks if a file is an allowed image extension.

Args:
    filename (string): path to a file

Returns:
    bool: True if the filename ends with a known image extension
)r   ÚIMG_EXTENSIONS)r   s    r   Úis_image_filer      s   € ô & h´Ó?Ð?r   Ú	directoryc                 óÊ   • [        S [        R                  " U 5       5       5      nU(       d  [        SU  S35      e[	        U5       VVs0 s H  u  p#X2_M	     nnnX4$ s  snnf )zOFinds the class folders in a dataset.

See :class:`DatasetFolder` for details.
c              3   óf   #   • U  H'  oR                  5       (       d  M  UR                  v •  M)     g 7f©N)Úis_dirÚname)Ú.0Úentrys     r   Ú	<genexpr>Úfind_classes.<locals>.<genexpr>)   s   é € ÐUÒ-B EÇlÁlÇn“Z�U—Z–ZÒ-Bùs   ‚1ž1z"Couldn't find any class folder in Ú.)ÚsortedÚosÚscandirÚFileNotFoundErrorÚ	enumerate)r   ÚclassesÚiÚcls_nameÚclass_to_idxs        r   Úfind_classesr/   $   sc   € ô
 ÑU¬R¯ZªZ¸	Ô-BÓUÓU€GÞÜÐ"DÀYÀKÈqÐ QÓRÐRä3<¸WÔ3EÔFÒ3E¡K A�H’KÑ3E€LÑFØÐ Ð ùó Gs   ÁAr.   Úis_valid_fileÚallow_emptyc                 ó€  ^• [         R                  R                  U 5      n Uc  [        U 5      u  pQOU(       d  [	        S5      eTSL =(       a    USL nTSL=(       a    USLnU(       d  U(       a  [	        S5      eTb  S[
        S[        4U4S jjn[        [        [
        /[        4   U5      n/ n[        5       n	[        UR                  5       5       Há  n
X   n[         R                  R                  X
5      n[         R                  R                  U5      (       d  ML  [        [         R                  " USS95       Hs  u  pÕn[        U5       H^  n[         R                  R                  Xß5      nU" U5      (       d  M1  UU4nUR                  U5        X©;  d  MM  U	R!                  U
5        M`     Mu     Mã     [        UR                  5       5      U	-
  nU(       aa  U(       dZ  S	S
R                  [        U5      5       S3nTb.  US[#        T[
        5      (       a  TOS
R                  T5       3-  n[%        U5      eU$ )zßGenerates a list of samples of a form (path_to_sample, class).

See :class:`DatasetFolder` for details.

Note: The class_to_idx parameter is here optional and will use the logic of the ``find_classes`` function
by default.
NzE'class_to_index' must have at least one entry to collect any samples.zMBoth extensions and is_valid_file cannot be None or not None at the same timeÚxr   c                 ó   >• [        U T5      $ r   )r   )r3   r   s    €r   r0   Ú#make_dataset.<locals>.is_valid_fileM   s   ø€ Ü-¨a°Ó<Ð<r   T)Úfollowlinksz$Found no valid file for the classes z, z. zSupported extensions are: )r'   ÚpathÚ
expanduserr/   Ú
ValueErrorr   Úboolr   r   Úsetr&   ÚkeysÚjoinÚisdirÚwalkÚappendÚaddr   r)   )r   r.   r   r0   r1   Ú_Ú	both_noneÚboth_somethingÚ	instancesÚavailable_classesÚtarget_classÚclass_indexÚ
target_dirÚrootÚfnamesÚfnamer7   ÚitemÚempty_classesÚmsgs     `                 r   Úmake_datasetrP   1   sö  ø€ ô —‘×"Ñ" 9Ó-€IàÑÜ& yÓ1‰ˆˆ<ÞÜÐ`ÓaÐaà˜dÐ"×< }¸Ð'<€IØ tÐ+×I°ÀTÐ0I€NÞ–NÜÐhÓiÐiàÑð	=œSð 	=¤T÷ 	=ô œ¤3 %¬ +Ñ.°Ó>€Mà€IÜ›ÐÜ˜|×0Ñ0Ó2Ö3ˆØ"Ñ0ˆÜ—W‘W—\‘\ )Ó:ˆ
Ü�w‰w�}‰}˜Z×(Ñ(ÙÜ%¤b§g¢g¨jÀdÑ&KÖL‰OˆD�VÜ ž�Ü—w‘w—|‘| DÓ0�Ù  ×&Ó&Ø Ð,�DØ×$Ñ$ TÔ*à#Õ<Ø)×-Ñ-¨lÖ;ó (ó  Mñ 4ô ˜×)Ñ)Ó+Ó,Ð/@Ñ@€MÞž[Ø4°T·Y±Y¼vÀmÓ?TÓ5UÐ4VÐVXÐYˆØÑ!ØÐ/¼jÈÔUX×>YÑ>Y±
Ð_c×_hÑ_hÐisÓ_tÐ/uÐvÑvˆCÜ Ó$Ð$àÐr   c                   ó~  ^ • \ rS rSrSr     SS\\\4   S\\/\	4   S\
\\S4      S\
\   S	\
\   S
\
\\/\4      S\SS4U 4S jjjr\   SS\\\4   S\\\4   S\
\\S4      S
\
\\/\4      S\S\\\\4      4S jj5       rS\\\4   S\\\   \\\4   4   4S jrS\S\\	\	4   4S jrS\4S jrSrU =r$ )ÚDatasetFolderém   a0  A generic data loader.

This default directory structure can be customized by overriding the
:meth:`find_classes` method.

Args:
    root (str or ``pathlib.Path``): Root directory path.
    loader (callable): A function to load a sample given its path.
    extensions (tuple[string]): A list of allowed extensions.
        both extensions and is_valid_file should not be passed.
    transform (callable, optional): A function/transform that takes in
        a sample and returns a transformed version.
        E.g, ``transforms.RandomCrop`` for images.
    target_transform (callable, optional): A function/transform that takes
        in the target and transforms it.
    is_valid_file (callable, optional): A function that takes path of a file
        and check if the file is a valid file (used to check of corrupt files)
        both extensions and is_valid_file should not be passed.
    allow_empty(bool, optional): If True, empty folders are considered to be valid classes.
        An error is raised on empty folders if False (default).

 Attributes:
    classes (list): List of the class names sorted alphabetically.
    class_to_idx (dict): Dict with items (class_name, class_index).
    samples (list): List of (sample path, class_index) tuples
    targets (list): The class_index value for each image in the dataset
NrJ   Úloaderr   .Ú	transformÚtarget_transformr0   r1   r   c                 ó  >• [         TU ]  XUS9  U R                  U R                  5      u  p‰U R	                  U R                  U	UUUS9n
X l        X0l        X€l        X�l        X l	        U
 Vs/ s H  o»S   PM	     snU l
        g s  snf )N)rU   rV   )r.   r   r0   r1   r
   )ÚsuperÚ__init__r/   rJ   rP   rT   r   r+   r.   ÚsamplesÚtargets)ÚselfrJ   rT   r   rU   rV   r0   r1   r+   r.   rZ   ÚsÚ	__class__s               €r   rY   ÚDatasetFolder.__init__Š   sŽ   ø€ ô 	‰Ñ˜ÐEUÐÑVØ $× 1Ñ 1°$·)±)Ó <ÑˆØ×#Ñ#Ø�I‰IØ%Ø!Ø'Ø#ð $ð 
ˆð ŒØ$ŒàŒØ(ÔØŒÙ&-Ó.¢g ˜!œ¡gÑ.ˆ�ùÒ.s   Á,Br   r.   c                 ó4   • Uc  [        S5      e[        XX#US9$ )a‚  Generates a list of samples of a form (path_to_sample, class).

This can be overridden to e.g. read files from a compressed zip file instead of from the disk.

Args:
    directory (str): root dataset directory, corresponding to ``self.root``.
    class_to_idx (Dict[str, int]): Dictionary mapping class name to class index.
    extensions (optional): A list of allowed extensions.
        Either extensions or is_valid_file should be passed. Defaults to None.
    is_valid_file (optional): A function that takes path of a file
        and checks if the file is a valid file
        (used to check of corrupt files) both extensions and
        is_valid_file should not be passed. Defaults to None.
    allow_empty(bool, optional): If True, empty folders are considered to be valid classes.
        An error is raised on empty folders if False (default).

Raises:
    ValueError: In case ``class_to_idx`` is empty.
    ValueError: In case ``extensions`` and ``is_valid_file`` are None or both are not None.
    FileNotFoundError: In case no valid file was found for any class.

Returns:
    List[Tuple[str, int]]: samples of a form (path_to_sample, class)
z*The class_to_idx parameter cannot be None.)r   r0   r1   )r9   rP   )r   r.   r   r0   r1   s        r   rP   ÚDatasetFolder.make_dataset¦   s.   € ð@ Ñô ÐIÓJÐJÜØ°
Ðepñ
ð 	
r   c                 ó   • [        U5      $ )uÔ  Find the class folders in a dataset structured as follows::

    directory/
    â”œâ”€â”€ class_x
    â”‚   â”œâ”€â”€ xxx.ext
    â”‚   â”œâ”€â”€ xxy.ext
    â”‚   â””â”€â”€ ...
    â”‚       â””â”€â”€ xxz.ext
    â””â”€â”€ class_y
        â”œâ”€â”€ 123.ext
        â”œâ”€â”€ nsdf3.ext
        â””â”€â”€ ...
        â””â”€â”€ asd932_.ext

This method can be overridden to only consider
a subset of classes, or to adapt to a different dataset directory structure.

Args:
    directory(str): Root directory path, corresponding to ``self.root``

Raises:
    FileNotFoundError: If ``dir`` has no class folders.

Returns:
    (Tuple[List[str], Dict[str, int]]): List of all classes and dictionary mapping each class to an index.
)r/   )r\   r   s     r   r/   ÚDatasetFolder.find_classesÏ   s   € ô6 ˜IÓ&Ð&r   Úindexc                 óÄ   • U R                   U   u  p#U R                  U5      nU R                  b  U R                  U5      nU R                  b  U R                  U5      nXC4$ )zu
Args:
    index (int): Index

Returns:
    tuple: (sample, target) where target is class_index of the target class.
)rZ   rT   rU   rV   )r\   rd   r7   ÚtargetÚsamples        r   Ú__getitem__ÚDatasetFolder.__getitem__ì   s^   € ð —|‘| EÑ*‰ˆØ—‘˜TÓ"ˆØ�>‰>Ñ%Ø—^‘^ FÓ+ˆFØ× Ñ Ñ,Ø×*Ñ*¨6Ó2ˆFàˆ~Ðr   c                 ó,   • [        U R                  5      $ r   )ÚlenrZ   )r\   s    r   Ú__len__ÚDatasetFolder.__len__ý   s   € Ü�4—<‘<Ó Ð r   )r.   r+   r   rT   rZ   r[   )NNNNF)NNF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r   r   r   r:   rY   ÚstaticmethodÚdictÚintÚlistrP   r/   rh   rl   Ú__static_attributes__Ú__classcell__©r^   s   @r   rR   rR   m   s¡  ø† ñð@ 15Ø(,Ø/3Ø9=Ø!ñ/à�C˜�IÑð/ð ˜#˜ ˜Ñ$ð/ð ˜U 3¨ 8™_Ñ-ð	/ð
 ˜HÑ%ð/ð # 8Ñ,ð/ð   ¨#¨°¨Ñ 5Ñ6ð/ð ð/ð 
÷/ð /ð8 ð 15Ø9=Ø!ñ&
Ø˜˜d˜Ñ#ð&
à˜3 ˜8‘nð&
ð ˜U 3¨ 8™_Ñ-ð&
ð   ¨#¨°¨Ñ 5Ñ6ð	&
ð
 ð&
ð 
ˆe�C˜�H‰oÑ	ô&
ó ð&
ðP' e¨C°¨IÑ&6ð '¸5ÀÀcÁÈDÐQTÐVYÐQYÉNÐAZÑ;[ô 'ð: ð ¨¨s°C¨x©ô ð"!˜÷ !ò !r   rR   )	z.jpgz.jpegz.pngz.ppmz.bmpz.pgmz.tifz.tiffz.webpr7   c                 óž   • [        U S5       n[        R                   " U5      nUR                  S5      sS S S 5        $ ! , (       d  f       g = f)NÚrbÚRGB)Úopenr	   Úconvert)r7   ÚfÚimgs      r   Ú
pil_loaderr�     s3   € ä	ˆd�DÔ	˜QÜ�jŠj˜‹mˆØ�{‰{˜5Ó!÷ 
×	×	ús	   �'>¾
Ac                 ód   • SS K n UR                  U 5      $ ! [         a    [        U 5      s $ f = f)Nr   )Úaccimager	   ÚOSErrorr�   )r7   rƒ   s     r   Úaccimage_loaderr…     s3   € Ûð Ø�~‰~˜dÓ#Ð#øÜó  ä˜$ÓÒð ús   † —/®/c                 óP   • SSK Jn  U" 5       S:X  a  [        U 5      $ [        U 5      $ )Nr   )Úget_image_backendrƒ   )Útorchvisionr‡   r…   r�   )r7   r‡   s     r   Údefault_loaderr‰     s&   € Ý-áÓ˜jÓ(Ü˜tÓ$Ð$ä˜$ÓÐr   c                   óŠ   ^ • \ rS rSrSrSS\SS4S\\\4   S\	\
   S\	\
   S\
\/\4   S	\	\
\/\4      S
\4U 4S jjjrSrU =r$ )ÚImageFolderi  aB  A generic data loader where the images are arranged in this way by default: ::

    root/dog/xxx.png
    root/dog/xxy.png
    root/dog/[...]/xxz.png

    root/cat/123.png
    root/cat/nsdf3.png
    root/cat/[...]/asd932_.png

This class inherits from :class:`~torchvision.datasets.DatasetFolder` so
the same methods can be overridden to customize the dataset.

Args:
    root (str or ``pathlib.Path``): Root directory path.
    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.
    loader (callable, optional): A function to load an image given its path.
    is_valid_file (callable, optional): A function that takes path of an Image file
        and check if the file is a valid file (used to check of corrupt files)
    allow_empty(bool, optional): If True, empty folders are considered to be valid classes.
        An error is raised on empty folders if False (default).

 Attributes:
    classes (list): List of the class names sorted alphabetically.
    class_to_idx (dict): Dict with items (class_name, class_index).
    imgs (list): List of (image path, class_index) tuples
NFrJ   rU   rV   rT   r0   r1   c           
      ó`   >• [         TU ]  UUUc  [        OS UUUUS9  U R                  U l        g )N)rU   rV   r0   r1   )rX   rY   r   rZ   Úimgs)r\   rJ   rU   rV   rT   r0   r1   r^   s          €r   rY   ÚImageFolder.__init__?  s@   ø€ ô 	‰ÑØØØ+Ñ3�N¸ØØ-Ø'Ø#ð 	ñ 	
ð —L‘Lˆ�	r   )r�   )rn   ro   rp   rq   rr   r‰   r   r   r   r   r   r   r:   rY   rw   rx   ry   s   @r   r‹   r‹     sŒ   ø† ñðD )-Ø/3Ø'5Ø9=Ø!ñ!à�C˜�IÑð!ð ˜HÑ%ð!ð # 8Ñ,ð	!ð
 ˜#˜ ˜Ñ$ð!ð   ¨#¨°¨Ñ 5Ñ6ð!ð ÷!ö !r   r‹   )NNNF)r'   Úos.pathÚpathlibr   Útypingr   r   r   r   r   ÚPILr	   Úvisionr   r   r   r:   r   r   rv   rt   ru   r/   rP   rR   r   r�   r…   r‰   r‹   © r   r   Ú<module>r•      s¥  ðÛ 	Û Ý ß 7Õ 7å å !ð
g¨ð 
g¸%ÀÀUÈ3ÐPSÈ8Á_Ð@TÑ:Uð 
gÐZ^ô 
gð	@˜Cð 	@ Dô 	@ð
!˜E # t )Ñ,ð 
!°°t¸C±yÀ$ÀsÈCÀxÁ.Ð7PÑ1Qô 
!ð .2Ø8<Ø59Øñ9Ø�S˜$�YÑð9à˜4  S ™>Ñ*ð9ð ˜˜s E¨#¨s¨(¡OÐ3Ñ4Ñ5ð9ð ˜H c U¨D [Ñ1Ñ2ð	9ð
 ð9ð 
ˆ%��S�‰/Ñõ9ôxQ!�Mô Q!ðh ]€ð"�U˜3 ˜9Ñ%ð "¨%¯+©+ô "ð ˜%  T 	Ñ*ð  ¨sô  ð ˜˜s D˜yÑ)ð  ¨cô  ô2!�-õ 2!r   