Ë
    Dêñi¹2  ã                   óÒ  — d dl Z d dlZ d dlmZ d dlmZmZmZmZm	Z	 d dl
mZ ddlmZ dede	eeed	f   f   d
efd„Zded
efd„Zde	eef   d
eee   eeef   f   fd„Z	 	 	 	 dde	eef   deeeef      dee	eeed	f   f      deeegef      ded
eeeef      fd„Z G d„ de«      ZdZde	eef   d
ej                  fd„Zde	eef   d
efd„Zde	eef   d
efd„Z G d„ de«      Zy)é    N)ÚPath)ÚAnyÚCallableÚcastÚOptionalÚUnion)ÚImageé   )ÚVisionDatasetÚfilenameÚ
extensions.Úreturnc                 ó~   — | j                  «       j                  t        |t        «      r|«      S t	        |«      «      S )a   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     ú]/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/torchvision/datasets/folder.pyÚhas_file_allowed_extensionr      s4   € ð �>‰>Ó×$Ñ$´:¸jÌ#Ô3N ZÓfÐfÔTYÐZdÓTeÓfÐfó    c                 ó"   — t        | t        «      S )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                 ó¾   — t        d„ t        j                  | «      D «       «      }|st        d| › d�«      ‚t	        |«      D ��ci c]  \  }}||“Œ
 }}}||fS c c}}w )zWFinds the class folders in a dataset.

    See :class:`DatasetFolder` for details.
    c              3   óV   K  — | ]!  }|j                  «       sŒ|j                  –— Œ# y ­w©N)Úis_dirÚname)Ú.0Úentrys     r   ú	<genexpr>zfind_classes.<locals>.<genexpr>)   s   è ø€ ÒU EÀeÇlÁlÅn�U—Z•ZÑUùs   ‚)˜)z"Couldn't find any class folder in ú.)ÚsortedÚosÚscandirÚFileNotFoundErrorÚ	enumerate)r   ÚclassesÚiÚcls_nameÚclass_to_idxs        r   Úfind_classesr.   $   sf   € ô
 ÑU¬R¯Z©Z¸	Ó-BÔUÓU€GÙÜÐ"DÀYÀKÈqÐ QÓRÐRä3<¸WÓ3E×F¡K A x�H˜a‘KÐF€LÑFØ�LÐ Ð ùó Gs   ÁAr-   Úis_valid_fileÚallow_emptyc                 ó  ‡— t         j                  j                  | «      } |€t        | «      \  }}n|st	        d«      ‚‰du xr |du }‰duxr |du}|s|rt	        d«      ‚‰�dt
        dt        fˆfd„}t        t        t
        gt        f   |«      }g }t        «       }	t        |j                  «       «      D ]Ô  }
||
   }t         j                  j                  | |
«      }t         j                  j                  |«      sŒHt        t        j                  |d¬«      «      D ]j  \  }}}t        |«      D ]V  }t         j                  j                  ||«      } ||«      sŒ,||f}|j                  |«       |
|	vsŒF|	j!                  |
«       ŒX Œl ŒÖ t        |j                  «       «      |	z
  }|rV|sTd	d
j                  t        |«      «      › d�}‰�)|dt#        ‰t
        «      r‰nd
j                  ‰«      › �z  }t%        |«      ‚|S )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                 ó   •— t        | ‰«      S r   )r   )r2   r   s    €r   r/   z#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   r/   r0   Ú_Ú	both_noneÚboth_somethingÚ	instancesÚavailable_classesÚtarget_classÚclass_indexÚ
target_dirÚrootÚfnamesÚfnamer5   ÚitemÚempty_classesÚmsgs     `                 r   Úmake_datasetrN   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°T·Y±Y¼vÀmÓ?TÓ5UÐ4VÐVXÐYˆØÐ!ØÐ/¼jÈÔUXÔ>Y±
Ð_c×_hÑ_hÐisÓ_tÐ/uÐvÑvˆCÜ Ó$Ð$àÐr   c                   óf  ‡ — e Zd ZdZ	 	 	 	 	 ddeeef   deegef   de	e
edf      de	e   de	e   d	e	eegef      d
eddfˆ fd„Ze	 	 	 ddeeef   deeef   de	e
edf      d	e	eegef      d
edee
eef      fd„«       Zdeeef   de
ee   eeef   f   fd„Zdede
eef   fd„Zdefd„Zˆ xZS )ÚDatasetFolderaŒ  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
    NrH   Úloaderr   .Ú	transformÚtarget_transformr/   r0   r   c                 ó&  •— t         ‰| �  |||¬«       | j                  | j                  «      \  }}	| j	                  | j                  |	|||¬«      }
|| _        || _        || _        |	| _        |
| _	        |
D �cg c]  }|d   ‘Œ	 c}| _
        y c c}w )N)rR   rS   )r-   r   r/   r0   r
   )ÚsuperÚ__init__r.   rH   rN   rQ   r   r*   r-   ÚsamplesÚtargets)ÚselfrH   rQ   r   rR   rS   r/   r0   r*   r-   rW   ÚsÚ	__class__s               €r   rV   zDatasetFolder.__init__Š   sš   ø€ ô 	‰Ñ˜¨ÐEUÐÔVØ $× 1Ñ 1°$·)±)Ó <Ñˆ�Ø×#Ñ#Ø�I‰IØ%Ø!Ø'Ø#ð $ó 
ˆð ˆŒØ$ˆŒàˆŒØ(ˆÔØˆŒØ&-Ö. ˜˜!›Ò.ˆ�ùÒ.s   Á9Br   r-   c                 ó<   — |€t        d«      ‚t        | ||||¬«      S )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   r/   r0   )r7   rN   )r   r-   r   r/   r0   s        r   rN   zDatasetFolder.make_dataset¦   s2   € ð@ Ðô ÐIÓJÐJÜØ�|°
È-Ðepô
ð 	
r   c                 ó   — t        |«      S )ut  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.   )rY   r   s     r   r.   zDatasetFolder.find_classesÏ   s   € ô6 ˜IÓ&Ð&r   Úindexc                 óÄ   — | j                   |   \  }}| j                  |«      }| j                  �| j                  |«      }| j                  �| j                  |«      }||fS )z�
        Args:
            index (int): Index

        Returns:
            tuple: (sample, target) where target is class_index of the target class.
        )rW   rQ   rR   rS   )rY   r^   r5   ÚtargetÚsamples        r   Ú__getitem__zDatasetFolder.__getitem__ì   sb   € ð —|‘| EÑ*‰ˆˆfØ—‘˜TÓ"ˆØ�>‰>Ð%Ø—^‘^ FÓ+ˆFØ× Ñ Ð,Ø×*Ñ*¨6Ó2ˆFà�vˆ~Ðr   c                 ó,   — t        | j                  «      S r   )ÚlenrW   )rY   s    r   Ú__len__zDatasetFolder.__len__ý   s   € Ü�4—<‘<Ó Ð r   )NNNNF)NNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r8   rV   ÚstaticmethodÚdictÚintÚlistrN   r.   rb   re   Ú__classcell__©r[   s   @r   rP   rP   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   rP   )	z.jpgz.jpegz.pngz.ppmz.bmpz.pgmz.tifz.tiffz.webpr5   c                 ó’   — t        | d«      5 }t        j                   |«      }|j                  d«      cd d d «       S # 1 sw Y   y xY w)NÚrbÚRGB)Úopenr	   Úconvert)r5   ÚfÚimgs      r   Ú
pil_loaderrw     s<   € ä	ˆd�DÓ	ð "˜QÜ�j‰j˜‹mˆØ�{‰{˜5Ó!÷"÷ "ò "ús	   �&=½Ac                 ób   — dd l }	 |j                  | «      S # t        $ r t        | «      cY S w xY w)Nr   )Úaccimager	   ÚOSErrorrw   )r5   ry   s     r   Úaccimage_loaderr{     s3   € Ûð Ø�~‰~˜dÓ#Ð#øÜò  ä˜$ÓÒð ús   † —.­.c                 óN   — ddl m}  |«       dk(  rt        | «      S t        | «      S )Nr   )Úget_image_backendry   )Útorchvisionr}   r{   rw   )r5   r}   s     r   Údefault_loaderr     s&   € Ý-áÓ˜jÒ(Ü˜tÓ$Ð$ä˜$ÓÐr   c                   ó|   ‡ — e Zd ZdZddeddfdeeef   dee	   dee	   de	ege
f   dee	egef      d	efˆ fd
„Zˆ xZS )ÚImageFoldera¢  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
    NFrH   rR   rS   rQ   r/   r0   c           	      ód   •— t         ‰| �  |||€t        nd ||||¬«       | j                  | _        y )N)rR   rS   r/   r0   )rU   rV   r   rW   Úimgs)rY   rH   rR   rS   rQ   r/   r0   r[   s          €r   rV   zImageFolder.__init__?  s@   ø€ ô 	‰ÑØØØ+Ð3�N¸ØØ-Ø'Ø#ð 	ô 	
ð —L‘Lˆ�	r   )rf   rg   rh   ri   r   r   r   r   r   r   r   r8   rV   rn   ro   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   r8   r   r   rm   rk   rl   r.   rN   rP   r   rw   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   