§
    >²¸jXÈ  ã                  óÜ  — d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d dlZd dlmZ d d
lmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z"m#Z# d dl$m%Z%m&Z& d dl'm(Z(m)Z) d dl*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z=  e>h d£¦  «        Z? G d„ de¦  «        Z@ G d„ de@¦  «        ZAe G d„ de@¦  «        ¦   «         ZBdS )é    ©ÚannotationsN)ÚABCÚabstractmethod)ÚIterator©Údeepcopy)Ú	dataclass)Úchain)ÚPath)Úcast)Útqdm)Ú_cv2)ÚClassifications)ÚCLASS_NAME_DATA_FIELD)Úload_coco_annotationsÚsave_coco_annotations)Úload_createml_annotationsÚsave_createml_annotations)Úload_labelme_annotationsÚsave_labelme_annotations)Úload_pascal_voc_annotationsÚsave_pascal_voc_annotations)Úload_yolo_annotationsÚsave_data_yamlÚsave_yolo_annotations)Úbuild_class_index_mappingÚcheck_no_basename_collisionsÚmap_detections_class_idÚmerge_class_listsÚsave_dataset_imagesÚtrain_test_split)Ú
Detections)Úwarn_deprecated)Úfind_duplicates>   ú.bmpú.jpgú.pngú.tifú.jpegú.tiffú.webpc                  óF   — e Zd Zedd„¦   «         Ze	 	 	 ddd„¦   «         ZdS )ÚBaseDatasetÚreturnÚintc                ó   — d S ©N© ©Úselfs    úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/supervision/dataset/core.pyÚ__len__zBaseDataset.__len__<   s   € àˆó    çš™™™™™é?NTÚsplit_ratioÚfloatÚrandom_stateú
int | NoneÚshuffleÚboolútuple[BaseDataset, BaseDataset]c                ó   — d S r2   r3   )r5   r:   r<   r>   s       r6   ÚsplitzBaseDataset.split@   s	   € ð 	ˆr8   ©r/   r0   ©r9   NT)r:   r;   r<   r=   r>   r?   r/   r@   )Ú__name__Ú
__module__Ú__qualname__r   r7   rB   r3   r8   r6   r.   r.   ;   sb   € € € € € Øðð ð ñ „^ðð ð !Ø#'Øð	ð ð ð ñ „^ðð ð r8   r.   c                  ól  — e Zd ZdZdEd
„ZdFd„ZdGd„ZdHd„ZdId„ZdJd„Z		 	 	 dKdLd#„Z
edMd&„¦   «         Z	 	 	 	 	 	 dNdOd1„Ze	 	 dPdQd3„¦   «         Ze	 	 	 dRdSd6„¦   «         Z	 	 	 	 	 	 	 	 dTdUd7„Ze	 dVdWd8„¦   «         Z	 	 dXdYd9„Ze	 dVdZd;„¦   «         Z	 	 	 d[d\d<„Ze	 	 dPdd=œd]d?„¦   «         Z	 	 	 	 	 	 	 	 d^d_dD„ZdS )`ÚDetectionDataseta  
    Contains information about a detection dataset. Handles lazy image loading
    and annotation retrieval, dataset splitting, conversions into multiple
    formats.

    Attributes:
        classes: List containing dataset class names.
        images:
            Accepts a list of image paths. Passing a dict
            (``Dict[str, np.ndarray]``) is deprecated in ``0.30.0`` and will
            be removed in ``0.33.0``; use a list of paths instead.
            When a list of paths is provided, images are loaded lazily on
            demand, which is more memory-efficient.
        annotations: Dictionary mapping
            image path to annotations. The dictionary keys match
            match the keys in `images` or entries in the list of
            image paths.
    Úclassesú	list[str]Úimagesú,list[str] | dict[str, npt.NDArray[np.uint8]]r   údict[str, Detections]r/   ÚNonec                óú  — || _         t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚d„  |j        ¦   «         D ¦   «         | _        t          j        | j         ¦  «        }| j                             ¦   «         D �]\  }}|j        }|€Œt          j        |j	        t
          j
        ¦  «        st          d|›d|j	        › d�¦  «        ‚||dk     |t          | j         ¦  «        k    z           }t          |¦  «        dk    rvt          | j         ¦  «        dk    rdndt          | j         ¦  «        d	z
  › d
�}	t          d|›dt          |d         ¦  «        › d|	› dt          | j         ¦  «        › d�	¦  «        ‚||         |j        t          <   �Œt          t                                |¦  «        ¦  «        | _        i | _        t)          |t           ¦  «        r|| _        t+          d¦  «         d S d S )Nú?The keys of the images and annotations dictionaries must match.c                ó4   — i | ]\  }}|t          |¦  «        “ŒS r3   r   )Ú.0Ú
image_pathÚ
annotations      r6   ú
<dictcomp>z-DetectionDataset.__init__.<locals>.<dictcomp>j   s6   € ð 
ð 
ð 
á&�
˜Jð � Ñ,Ô,ð
ð 
ð 
r8   zDetection annotation for image z1 contains non-integer class_id values with dtype ú.r   Úemptyz[0, é   ú]z contains class_id z, outside the valid range z for z	 classes.z�Passing a `Dict[str, np.ndarray]` into `DetectionDataset` is deprecated in `0.30.0` and will be removed in `0.33.0`. Use a list of paths `List[str]` instead.)rJ   ÚsetÚ
ValueErrorÚitemsr   ÚnpÚarrayÚclass_idÚ
issubdtypeÚdtypeÚintegerÚlenr0   Údatar   ÚlistÚdictÚfromkeysÚimage_pathsÚ_images_in_memoryÚ
isinstancer$   )
r5   rJ   rL   r   Ú
np_classesrT   rU   Ú	class_idsÚinvalid_class_idsÚvalid_ranges
             r6   Ú__init__zDetectionDataset.__init__^   sw  € ð ˆŒåˆv‰;Œ;�#˜kÑ*Ô*Ò*Ð*ÝØQñô ð ð
ð 
à*;¨+Ô*;Ñ*=Ô*=ð
ñ 
ô 
ˆÔõ
 ”X˜dœlÑ+Ô+ˆ
Ø&*Ô&6×&<Ò&<Ñ&>Ô&>ð 	Kñ 	KÑ"ˆJ˜
Ø"Ô+ˆIØÐ ØÝ”= ¤µ"´*Ñ=Ô=ð Ý ðQ°jð Qð QØ>G¼oðQð Qð Qñô ð ð
 !*Ø˜Q’ 9µ°D´LÑ0AÔ0AÒ#AÑBô!Ðõ Ð$Ñ%Ô%¨Ò)Ð)õ ˜4œ<Ñ(Ô(¨AÒ-Ð-ð �Gà8¥ D¤LÑ 1Ô 1°AÑ 5Ð8Ð8Ð8ð õ
 !ðL°jð Lð LÝ #Ð$5°aÔ$8Ñ 9Ô 9ðLð Là(ðLð Lå/2°4´<Ñ/@Ô/@ðLð Lð Lñô ð ð 6@À	Ô5JˆJŒOÕ1Ñ2Ñ2õ  ¥§¢¨fÑ 5Ô 5Ñ6Ô6ˆÔàCEˆÔÝ�f�dÑ#Ô#ð 	Ø%+ˆDÔ"Ýð7ñô ð ð ð ð	ð 	r8   rT   Ústrúnpt.NDArray[np.uint8]c                óÎ   — | j         r| j         |         S t          j        |¦  «        }|€t          d|› �¦  «        ‚t	          t
          j        t          j                 |¦  «        S ©z!Assumes that image is in dataset.Nz Could not read image from path: ©	rj   Úcv2Úimreadr\   r   ÚnptÚNDArrayr^   Úuint8©r5   rT   Úimages      r6   Ú
_get_imagezDetectionDataset._get_image—   ó_   € àÔ!ð 	6ØÔ)¨*Ô5Ð5Ý”
˜:Ñ&Ô&ˆØˆ=ÝÐLÀ
ÐLÐLÑMÔMÐMÝ•C”K¥¤Ô)¨5Ñ1Ô1Ð1r8   r0   c                óR   — t          | j        ¦  «        pt          | j        ¦  «        S r2   ©rd   rj   ri   r4   s    r6   r7   zDetectionDataset.__len__    ó#   € Ý�4Ô)Ñ*Ô*ÐC­c°$Ô2BÑ.CÔ.CÐCr8   Úiú-tuple[str, npt.NDArray[np.uint8], Detections]c                ój   — | j         |         }|                      |¦  «        }| j        |         }|||fS ©z
        Returns:
            The image path, image data,
                and its corresponding annotation at index i.
        ©ri   r}   r   ©r5   r‚   rT   r|   rU   s        r6   Ú__getitem__zDetectionDataset.__getitem__£   ó<   € ð Ô% aÔ(ˆ
Ø—’ 
Ñ+Ô+ˆØÔ% jÔ1ˆ
Ø˜5 *Ð,Ð,r8   ú7Iterator[tuple[str, npt.NDArray[np.uint8], Detections]]c              #  ón   K  — t          t          | ¦  «        ¦  «        D ]}| |         \  }}}|||fV — ŒdS ©z¨
        Iterate over the images and annotations in the dataset.

        Yields:
            Tuples containing the image path, image data, and its annotation.
        N©Úrangerd   r‡   s        r6   Ú__iter__zDetectionDataset.__iter__®   sU   è è € õ •s˜4‘y”yÑ!Ô!ð 	0ð 	0ˆAØ,0°¬GÑ)ˆJ˜˜zØ˜e ZÐ/Ð/Ð/Ð/Ð/ð	0ð 	0r8   ÚotherÚobjectr?   c                óz  — t          |t          ¦  «        sdS | j        |j        k    rdS | j        |j        k    rdS | j        s|j        r_t          j        t          | j                             ¦   «         ¦  «        t          |j                             ¦   «         ¦  «        ¦  «        sdS | j	        |j	        k    rdS dS ©NFT)
rk   rI   rJ   ri   rj   r^   Úarray_equalrf   Úvaluesr   ©r5   r�   s     r6   Ú__eq__zDetectionDataset.__eq__¹   sÃ   € Ý˜%Õ!1Ñ2Ô2ð 	Ø�5àŒ<˜5œ=Ò(Ð(Ø�5àÔ˜uÔ0Ò0Ð0Ø�5àÔ!ð 	 UÔ%<ð 	Ý”>Ý�TÔ+×2Ò2Ñ4Ô4Ñ5Ô5Ý�UÔ,×3Ò3Ñ5Ô5Ñ6Ô6ñô ð ð �uàÔ˜uÔ0Ò0Ð0Ø�5àˆtr8   r9   NTr:   r;   r<   r=   r>   ú)tuple[DetectionDataset, DetectionDataset]c                ó0  ‡ — t          ‰ j        |||¬¦  «        \  }}ˆ fd„|D ¦   «         }ˆ fd„|D ¦   «         }t          ‰ j        ||¬¦  «        }t          ‰ j        ||¬¦  «        }	‰ j        r&ˆ fd„|D ¦   «         |_        ˆ fd„|D ¦   «         |	_        ||	fS )aR  
        Splits the dataset into two parts (training and testing)
            using the provided split_ratio. The input dataset is not mutated.

        Args:
            split_ratio: The ratio of the training
                set to the entire dataset.
            random_state: The seed for the random number generator.
                This is used for reproducibility.
            shuffle: Whether to shuffle the data before splitting.

        Returns:
            A tuple containing
                the training and testing datasets.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> ds = sv.DetectionDataset(
            ...     classes=['dog', 'person'],
            ...     images={
            ...         'img1.jpg': np.zeros((100, 100, 3), dtype=np.uint8),
            ...         'img2.jpg': np.zeros((100, 100, 3), dtype=np.uint8),
            ...     },
            ...     annotations={
            ...         'img1.jpg': sv.Detections(xyxy=np.array([[10, 10, 20, 20]])),
            ...         'img2.jpg': sv.Detections(xyxy=np.array([[30, 30, 40, 40]])),
            ...     }
            ... )
            >>> train_ds, test_ds = ds.split(split_ratio=0.5, random_state=42)
            >>> len(train_ds), len(test_ds)
            (1, 1)

            ```
        ©re   Útrain_ratior<   r>   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r   ©rS   Úpathr5   s     €r6   rV   z*DetectionDataset.split.<locals>.<dictcomp>  ó#   ø€ ÐRÐRÐR¸d˜T 4Ô#3°DÔ#9ÐRÐRÐRr8   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r   r�   s     €r6   rV   z*DetectionDataset.split.<locals>.<dictcomp>  ó#   ø€ ÐPÐPÐP¸T˜D $Ô"2°4Ô"8ÐPÐPÐPr8   ©rJ   rL   r   c                ó,   •— i | ]}|‰j         |         “ŒS r3   ©rj   r�   s     €r6   rV   z*DetectionDataset.split.<locals>.<dictcomp>  s0   ø€ ð /ð /ð /Ø7;��dÔ,¨TÔ2ð/ð /ð /r8   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r¤   r�   s     €r6   rV   z*DetectionDataset.split.<locals>.<dictcomp>  s0   ø€ ð .ð .ð .Ø7;��dÔ,¨TÔ2ð.ð .ð .r8   )r"   ri   rI   rJ   rj   )
r5   r:   r<   r>   Útrain_pathsÚ
test_pathsÚtrain_annotationsÚtest_annotationsÚtrain_datasetÚtest_datasets
   `         r6   rB   zDetectionDataset.splitÏ   s  ø€ õV #3ØÔ!Ø#Ø%Øð	#
ñ #
ô #
Ñˆ�Zð SÐRÐRÐRÀkÐRÑRÔRÐØPÐPÐPÐPÀZÐPÑPÔPÐå(Ø”LØØ)ð
ñ 
ô 
ˆõ
 (Ø”LØØ(ð
ñ 
ô 
ˆð
 Ô!ð 	ð/ð /ð /ð /Ø?Jð/ñ /ô /ˆMÔ+ð.ð .ð .ð .Ø?Ið.ñ .ô .ˆLÔ*ð ˜lÐ*Ð*r8   Údataset_listúlist[DetectionDataset]c                ó2  ‡‡— dd„Šdd„Št          ˆfd„|D ¦   «         ¦  «        }t          ˆfd„|D ¦   «         ¦  «        }|s|st          d	¦  «        ‚i }|D ]}|                     |j        ¦  «         Œt	          t          j        d
„ |D ¦   «         ¦  «        ¦  «        }t	          t                               |¦  «        ¦  «        }t          |¦  «        t          |¦  «        k    r"t          |¦  «        }t          d|› d�¦  «        ‚|}t          d„ |D ¦   «         ¬¦  «        }	i }
|D ]} |
j        |j        ¦  «         Œ|D ]<}t          |j        |	¬¦  «        }|j        D ]}t!          ||
|         ¬¦  «        |
|<   ŒŒ= | |	||
¬¦  «        }|r||_        |S )a  
        Merge a list of `DetectionDataset` objects into a single
            `DetectionDataset` object.

        This method takes a list of `DetectionDataset` objects and combines
        their respective fields (`classes`, `images`,
        `annotations`) into a single `DetectionDataset` object.

        Args:
            dataset_list: A list of `DetectionDataset`
                objects to merge.

        Returns:
            A single `DetectionDataset` object containing
            the merged data from the input list.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> ds_1 = sv.DetectionDataset(
            ...     classes=['dog', 'person'],
            ...     images={'img1.jpg': np.zeros((100, 100, 3), dtype=np.uint8)},
            ...     annotations={'img1.jpg': sv.Detections.empty()}
            ... )
            >>> len(ds_1)
            1
            >>> ds_1.classes
            ['dog', 'person']
            >>> ds_2 = sv.DetectionDataset(
            ...     classes=['cat'],
            ...     images={'img2.jpg': np.zeros((100, 100, 3), dtype=np.uint8)},
            ...     annotations={'img2.jpg': sv.Detections.empty()}
            ... )
            >>> len(ds_2)
            1
            >>> ds_2.classes
            ['cat']
            >>> ds_merged = sv.DetectionDataset.merge([ds_1, ds_2])
            >>> len(ds_merged)
            2
            >>> ds_merged.classes
            ['cat', 'dog', 'person']

            ```
        ÚdatasetrI   r/   r?   c                ób   — t          | j        ¦  «        dk    pt          | j        ¦  «        dk    S ©Nr   r€   ©r¯   s    r6   Úis_in_memoryz,DetectionDataset.merge.<locals>.is_in_memoryH  s.   € Ý�wÔ0Ñ1Ô1°AÒ5ÐV½¸WÔ=PÑ9QÔ9QÐUVÒ9VÐVr8   c                ó2   — t          | j        ¦  «        dk    S r±   )rd   rj   r²   s    r6   Úis_lazyz'DetectionDataset.merge.<locals>.is_lazyK  s   € Ý�wÔ0Ñ1Ô1°QÒ6Ð6r8   c                ó&   •— g | ]} ‰|¦  «        ‘ŒS r3   r3   )rS   r¯   r³   s     €r6   ú
<listcomp>z*DetectionDataset.merge.<locals>.<listcomp>N  s#   ø€ ÐOÐOÐO°w˜\˜\¨'Ñ2Ô2ÐOÐOÐOr8   c                ó&   •— g | ]} ‰|¦  «        ‘ŒS r3   r3   )rS   r¯   rµ   s     €r6   r·   z*DetectionDataset.merge.<locals>.<listcomp>O  s#   ø€ ÐEÐEÐE¨W˜˜ Ñ(Ô(ÐEÐEÐEr8   z>Merging lazy and in-memory DetectionDatasets is not supported.c              3  ó$   K  — | ]}|j         V — Œd S r2   )ri   ©rS   r¯   s     r6   ú	<genexpr>z)DetectionDataset.merge.<locals>.<genexpr>Z  s%   è è € ÐPÐP¸ Ô 3ÐPÐPÐPÐPÐPÐPr8   zImage paths z  are not unique across datasets.c                ó   — g | ]	}|j         ‘Œ
S r3   )rJ   rº   s     r6   r·   z*DetectionDataset.merge.<locals>.<listcomp>e  s   € ÐEÐEÐE¨W˜œÐEÐEÐEr8   )Úclass_lists)Úsource_classesÚtarget_classes)Úsource_to_target_mappingÚ
detectionsr¢   )r¯   rI   r/   r?   )Úallr\   Úupdaterj   rf   r   Úfrom_iterablerg   rh   rd   r%   r    r   r   rJ   ri   r   )Úclsr¬   Úall_in_memoryÚall_lazyÚimages_in_memoryr¯   ri   Úimage_paths_uniqueÚ
duplicatesrJ   r   Úclass_index_mappingrT   Úmerged_datasetr³   rµ   s                 @@r6   ÚmergezDetectionDataset.merge  s]  øø€ ðb	Wð 	Wð 	Wð 	Wð	7ð 	7ð 	7ð 	7õ ÐOÐOÐOÐOÀ,ÐOÑOÔOÑPÔPˆÝÐEÐEÐEÐE¸ÐEÑEÔEÑFÔFˆØð 	 Xð 	ÝØPñô ð ð ÐØ#ð 	?ð 	?ˆGØ×#Ò# GÔ$=Ñ>Ô>Ð>Ð>åÝÔÐPÐPÀ<ÐPÑPÔPÑPÔPñ
ô 
ˆõ "¥$§-¢-°Ñ"<Ô"<Ñ=Ô=ÐÝˆ{ÑÔ�sÐ#5Ñ6Ô6Ò6Ð6Ý(¨Ñ5Ô5ˆJÝØK˜zÐKÐKÐKñô ð ð )ˆå#ØEÐE¸ÐEÑEÔEð
ñ 
ô 
ˆð ˆØ#ð 	4ð 	4ˆGØˆKÔ˜wÔ2Ñ3Ô3Ð3Ð3Ø#ð 	ð 	ˆGÝ";Ø&œ¸wð#ñ #ô #Ðð &Ô1ð ð �
Ý*AØ-@Ø*¨:Ô6ð+ñ +ô +�˜JÑ'Ð'ðð ˜ØØØ#ð
ñ 
ô 
ˆð
 ð 	@Ø/?ˆNÔ,ØÐr8   ç        ç      ð?FÚimages_directory_pathú
str | NoneÚannotations_directory_pathÚmin_image_area_percentageÚmax_image_area_percentageÚapproximation_percentageÚshow_progressc                óÈ   — |rt          | j        d„ d¬¦  «         |rt          | j        d„ d¬¦  «         |rt          | ||¬¦  «         |rt          | |||||¬¦  «         dS dS )	a  
        Exports the dataset to PASCAL VOC format. This method saves the images
        and their corresponding annotations in PASCAL VOC format. Both output
        layouts are preflighted before any files are written so a collision in
        either target fails without partial output.

        Args:
            images_directory_path: The path to the directory
                where the images should be saved.
                If not provided, images will not be saved.
            annotations_directory_path: The path to
                the directory where the annotations in PASCAL VOC format should be
                saved. If not provided, annotations will not be saved.
            min_image_area_percentage: The minimum percentage of
                detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            max_image_area_percentage: The maximum percentage
                of detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            approximation_percentage: The percentage of
                polygon points to be removed from the input polygon,
                in the range [0, 1). Argument is used only for segmentation datasets.
            show_progress: If True, display a progress bar during saving.

        Raises:
            ValueError: If two image paths share the same basename (when
                images_directory_path is set) or the same stem (when
                annotations_directory_path is set), which would cause one
                output file to overwrite another. Rename images to ensure
                unique basenames before exporting a merged dataset.
        c                ó*   — t          | ¦  «        j        S r2   ©r   Úname©rT   s    r6   ú<lambda>z0DetectionDataset.as_pascal_voc.<locals>.<lambda>«  ó   € ¥t¨JÑ'7Ô'7Ô'<€ r8   r|   ©ri   ÚkeyÚoutput_kindc                ó0   — t          | ¦  «        j        › d�S )Nz.xml©r   ÚstemrÛ   s    r6   rÜ   z0DetectionDataset.as_pascal_voc.<locals>.<lambda>±  s   € ­$¨zÑ*:Ô*:Ô*?Ð'EÐ'EÐ'E€ r8   zPascal VOC annotation©r¯   rÐ   rÖ   )r¯   rÒ   rÓ   rÔ   rÕ   rÖ   N)r   ri   r!   r   )r5   rÐ   rÒ   rÓ   rÔ   rÕ   rÖ   s          r6   Úas_pascal_voczDetectionDataset.as_pascal_voc~  sÔ   € ðT !ð 	Ý(Ø Ô,Ø<Ð<Ø#ðñ ô ð ð
 &ð 	Ý(Ø Ô,ØEÐEØ3ðñ ô ð ð !ð 	ÝØØ&;Ø+ðñ ô ð ð
 &ð 	Ý'ØØ+EØ*CØ*CØ)AØ+ðñ ô ð ð ð ð	ð 	r8   Úforce_masksc                óT   — t          ||||¬¦  «        \  }}}t          |||¬¦  «        S )a:  
        Creates a Dataset instance from PASCAL VOC formatted data.

        Args:
            images_directory_path: Path to the directory containing the images.
            annotations_directory_path: Path to the directory
                containing the PASCAL VOC XML annotations.
            force_masks: If True, forces masks to
                be loaded for all annotations, regardless of whether they are present.
            show_progress: If True, display a progress bar during loading.

        Returns:
            A DetectionDataset instance containing
                the loaded images and annotations.

        Examples:
            ```python
            import roboflow
            from roboflow import Roboflow
            import supervision as sv

            roboflow.login()

            rf = Roboflow()

            project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
            dataset = project.version(PROJECT_VERSION).download("voc")

            ds = sv.DetectionDataset.from_pascal_voc(
                images_directory_path=f"{dataset.location}/train/images",
                annotations_directory_path=f"{dataset.location}/train/labels",
                # pass show_progress=True to enable a tqdm progress bar
            )

            ds.classes
            # ['dog', 'person']
            ```
        )rÐ   rÒ   ræ   rÖ   r¢   )r   rI   )rÅ   rÐ   rÒ   ræ   rÖ   rJ   ri   r   s           r6   Úfrom_pascal_vocz DetectionDataset.from_pascal_vocÅ  sM   € õ^ -HØ"7Ø'AØ#Ø'ð	-
ñ -
ô -
Ñ)ˆ�˜kõ  Ø K¸[ð
ñ 
ô 
ð 	
r8   Údata_yaml_pathÚis_obbc                óX   — t          ||||||¬¦  «        \  }}}	t          |||	¬¦  «        S )aÊ  
        Creates a Dataset instance from YOLO formatted data.

        Args:
            images_directory_path: The path to the
                directory containing the images.
            annotations_directory_path: The path to the directory
                containing the YOLO annotation files.
            data_yaml_path: The path to the data
                YAML file containing class information.
            force_masks: If True, forces
                masks to be loaded for all annotations,
                regardless of whether they are present.
            is_obb: If True, loads the annotations in OBB format.
                OBB annotations are defined as `[class_id, x, y, x, y, x, y, x, y]`,
                where pairs of [x, y] are box corners.
            show_progress: If True, display a progress bar during loading.

        Returns:
            A DetectionDataset instance
                containing the loaded images and annotations.

        Examples:
            ```python
            import roboflow
            from roboflow import Roboflow
            import supervision as sv

            roboflow.login()
            rf = Roboflow()

            project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
            dataset = project.version(PROJECT_VERSION).download("yolov5")

            ds = sv.DetectionDataset.from_yolo(
                images_directory_path=f"{dataset.location}/train/images",
                annotations_directory_path=f"{dataset.location}/train/labels",
                data_yaml_path=f"{dataset.location}/data.yaml",
                # pass show_progress=True to enable a tqdm progress bar
            )

            ds.classes
            # ['dog', 'person']
            ```
        )rÐ   rÒ   ré   ræ   rê   rÖ   r¢   )r   rI   )
rÅ   rÐ   rÒ   ré   ræ   rê   rÖ   rJ   ri   r   s
             r6   Ú	from_yolozDetectionDataset.from_yoloÿ  sS   € õn -BØ"7Ø'AØ)Ø#ØØ'ð-
ñ -
ô -
Ñ)ˆ�˜kõ  Ø K¸[ð
ñ 
ô 
ð 	
r8   c	           	     ód  — |r3|dk    s|dk    s|dk    r!ddl }	|	                     dt          d¬¦  «         |rt          | j        d„ d	¬
¦  «         |rt          | j        d„ d¬
¦  «         |�t          | ||¬¦  «         |�t          | ||||||¬¦  «         |�t          || j        ¬¦  «         dS dS )aP  
        Exports the dataset to YOLO format. This method saves the
        images and their corresponding annotations in YOLO format.

        Args:
            images_directory_path: The path to the
                directory where the images should be saved.
                If not provided, images will not be saved.
            annotations_directory_path: The path to the
                directory where the annotations in
                YOLO format should be saved. If not provided,
                annotations will not be saved.
            data_yaml_path: The path where the data.yaml
                file should be saved.
                If not provided, the file will not be saved.
            min_image_area_percentage: The minimum percentage of
                detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            max_image_area_percentage: The maximum percentage
                of detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            approximation_percentage: The percentage of polygon points to
                be removed from the input polygon, in the range [0, 1).
                This is useful for simplifying the annotations.
                Argument is used only for segmentation datasets.
            is_obb: If True, exports annotations in OBB format
                (`class_id x1 y1 x2 y2 x3 y3 x4 y4`) using the oriented
                corners stored in `detections.data["xyxyxyxy"]`. Mirrors
                `from_yolo(..., is_obb=True)`. Masks are ignored when
                `is_obb=True`.
            show_progress: If True, display a progress bar during saving.

        Raises:
            ValueError: If two image paths share the same basename (when
                images_directory_path is set) or the same annotation
                file name (when annotations_directory_path is set),
                which would cause one output file to overwrite another.
        rÎ   rÏ   r   Nz¬`min_image_area_percentage`, `max_image_area_percentage`, and `approximation_percentage` have no effect when `is_obb=True`; OBB annotations use corner coordinates directly.é   )Ú
stacklevelc                ó*   — t          | ¦  «        j        S r2   rÙ   rÛ   s    r6   rÜ   z*DetectionDataset.as_yolo.<locals>.<lambda>‡  rÝ   r8   r|   rÞ   c                ó0   — t          | ¦  «        j        dz   S )Nz.txtrâ   rÛ   s    r6   rÜ   z*DetectionDataset.as_yolo.<locals>.<lambda>�  s   € ¥t¨JÑ'7Ô'7Ô'<¸vÑ'E€ r8   zYOLO annotationrä   )r¯   rÒ   rÓ   rÔ   rÕ   rÖ   rê   )ré   rJ   )	ÚwarningsÚwarnÚUserWarningr   ri   r!   r   r   rJ   )
r5   rÐ   rÒ   ré   rÓ   rÔ   rÕ   rê   rÖ   rò   s
             r6   Úas_yolozDetectionDataset.as_yoloB  sG  € ðf ð 	Ø%¨Ò,Ð,Ø(¨CÒ/Ð/Ø'¨3Ò.Ð.àˆOˆOˆOà�MŠMðCõ Øð ñ ô ð ð !ð 	Ý(Ø Ô,Ø<Ð<Ø#ðñ ô ð ð
 &ð 	Ý(Ø Ô,ØEÐEØ-ðñ ô ð ð !Ð,ÝØØ&;Ø+ðñ ô ð ð
 &Ð1Ý!ØØ+EØ*CØ*CØ)AØ+Øðñ ô ð ð Ð%Ý¨.À$Ä,ÐOÑOÔOÐOÐOÐOð &Ð%r8   c                óR   — t          |||¬¦  «        \  }}}t          |||¬¦  «        S )aA  
        Creates a Dataset instance from LabelMe formatted data.

        LabelMe stores one JSON file per image, each containing a list of
        ``shapes``. ``rectangle`` shapes are loaded as bounding boxes and
        ``polygon`` shapes as masks (with their bounding boxes); other shape
        types are skipped. Class names are inferred from the labels present in
        the files. When an image file contains a ``polygon`` shape, or when
        ``force_masks=True`` is set, both ``rectangle`` and ``polygon`` shapes
        produce masks: rectangles via a four-corner polygon fill.

        Args:
            images_directory_path: The path to the
                directory containing the images.
            annotations_directory_path: The path to the directory
                containing the LabelMe ``.json`` annotation files.
            force_masks: If True, forces masks to be loaded for all
                annotations, regardless of whether polygon shapes are present.
                Requires ``imageWidth`` and ``imageHeight`` in every JSON file.

        Returns:
            A DetectionDataset instance containing
                the loaded images and annotations.

        Raises:
            ValueError: If an annotation is malformed - for example
                ``imagePath`` is empty or resolves to ``..``, a shape is
                missing its ``label`` or ``points``, or a mask is required but
                ``imageWidth`` / ``imageHeight`` are missing or zero.

        Examples:
            ```python
            import supervision as sv

            ds = sv.DetectionDataset.from_labelme(
                images_directory_path="<IMAGES_DIRECTORY_PATH>",
                annotations_directory_path="<ANNOTATIONS_DIRECTORY_PATH>",
            )

            ds.classes
            # ['dog', 'person']
            ```
        )rÐ   rÒ   ræ   r¢   )r   rI   )rÅ   rÐ   rÒ   ræ   rJ   ri   r   s          r6   Úfrom_labelmezDetectionDataset.from_labelme¤  sJ   € õd -EØ"7Ø'AØ#ð-
ñ -
ô -
Ñ)ˆ�˜kõ
  Ø K¸[ð
ñ 
ô 
ð 	
r8   c                óV   — |�t          | |¬¦  «         |�t          | |¬¦  «         dS dS )a×  
        Exports the dataset to LabelMe format. This method saves the images and
        their corresponding annotations as per-image LabelMe ``.json`` files.
        Masked detections are written as ``polygon`` shapes whose vertices
        approximate the mask contour, so masks are not bit-exact on round-trip.
        Because the bounding box is recomputed from the quantized polygon contour
        on re-import, bounding boxes for masked detections may also shift by
        approximately one pixel after a save-load cycle.

        Args:
            images_directory_path: The path to the directory
                where the images should be saved.
                If not provided, images will not be saved.
            annotations_directory_path: The path to the directory where the
                LabelMe ``.json`` files should be saved.
                If not provided, annotations will not be saved.

        Examples:
            ```python
            import supervision as sv

            ds = sv.DetectionDataset(...)

            ds.as_labelme(
                images_directory_path="<IMAGES_DIRECTORY_PATH>",
                annotations_directory_path="<ANNOTATIONS_DIRECTORY_PATH>",
            )
            ```
        N)r¯   rÐ   )r¯   rÒ   )r!   r   )r5   rÐ   rÒ   s      r6   Ú
as_labelmezDetectionDataset.as_labelmeß  s_   € ðD !Ð,ÝØÐ4Iðñ ô ð ð &Ð1Ý$ØØ+Eðñ ô ð ð ð ð 2Ð1r8   Úannotations_pathc                óR   — t          |||¬¦  «        \  }}}t          |||¬¦  «        S )a_  
        Creates a Dataset instance from CreateML formatted data.

        CreateML stores object-detection annotations in a single JSON file as a
        list of per-image entries, with each box expressed as a pixel-space
        centre point plus width and height. Class names are inferred from the
        labels present in the file.

        Args:
            images_directory_path: The path to the directory containing the
                images.
            annotations_path: The path to the CreateML json annotation file.
            show_progress: If True, display a progress bar during loading.

        Returns:
            A DetectionDataset instance containing the loaded images and
            annotations.

        Examples:
            ```python
            import roboflow
            from roboflow import Roboflow
            import supervision as sv

            roboflow.login()
            rf = Roboflow()

            project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
            dataset = project.version(PROJECT_VERSION).download("createml")

            ds = sv.DetectionDataset.from_createml(
                images_directory_path=f"{dataset.location}/train",
                annotations_path=f"{dataset.location}/train/_annotations.createml.json",
            )

            ds.classes
            # ['dog', 'person']
            ```
        )rÐ   rú   rÖ   r¢   )r   rI   )rÅ   rÐ   rú   rÖ   rJ   ri   r   s          r6   Úfrom_createmlzDetectionDataset.from_createml  sJ   € õ\ -FØ"7Ø-Ø'ð-
ñ -
ô -
Ñ)ˆ�˜kõ
  Ø K¸[ð
ñ 
ô 
ð 	
r8   c                óX   — |�t          | ||¬¦  «         |�t          | |¬¦  «         dS dS )aÆ  
        Exports the dataset to CreateML format. This method saves the
        images and their corresponding annotations in CreateML format.

        Args:
            images_directory_path: The path to the directory where the images
                should be saved. If not provided, images will not be saved.
            annotations_path: The path to the CreateML json annotation file.
                If not provided, the annotations will not be saved.
            show_progress: If True, display a progress bar while saving images.

        Returns:
            None. Side-effects only: writes images and/or annotation file.

        Examples:
            ```python
            import supervision as sv

            ds = sv.DetectionDataset(classes=["dog"], images=[], annotations={})
            ds.as_createml(
                images_directory_path="/tmp/images",
                annotations_path="/tmp/annotations.json",
            )
            ```
        Nrä   )r¯   rú   )r!   r   )r5   rÐ   rú   rÖ   s       r6   Úas_createmlzDetectionDataset.as_createmlB  sa   € ð> !Ð,ÝØØ&;Ø+ðñ ô ð ð
 Ð'Ý%ØØ!1ðñ ô ð ð ð ð (Ð'r8   )Úuse_iscrowdrÿ   c               óV   — t          |||||¬¦  «        \  }}}t          |||¬¦  «        S )aŸ  
        Creates a Dataset instance from COCO formatted data.

        Args:
            images_directory_path: The path to the
                directory containing the images.
            annotations_path: The path to the json annotation files.
            force_masks: If True,
                forces masks to be loaded for all annotations,
                regardless of whether they are present.
            show_progress: If True, display a progress bar during loading.
            use_iscrowd: If True, includes COCO ``iscrowd`` and ``area``
                annotation fields in ``Detections.data``.
        Returns:
            A DetectionDataset instance containing
                the loaded images and annotations.

        Examples:
            ```python
            import roboflow
            from roboflow import Roboflow
            import supervision as sv

            roboflow.login()
            rf = Roboflow()

            project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
            dataset = project.version(PROJECT_VERSION).download("coco")

            ds = sv.DetectionDataset.from_coco(
                images_directory_path=f"{dataset.location}/train",
                annotations_path=f"{dataset.location}/train/_annotations.coco.json",
                # pass show_progress=True to enable a tqdm progress bar
            )

            ds.classes
            # ['dog', 'person']
            ```
        )rÐ   rú   ræ   rÿ   rÖ   r¢   )r   rI   )	rÅ   rÐ   rú   ræ   rÖ   rÿ   rJ   rL   r   s	            r6   Ú	from_cocozDetectionDataset.from_cocom  sF   € õb (=Ø"7Ø-Ø#Ø#Ø'ð(
ñ (
ô (
Ñ$ˆ�˜õ  ¨¸ÈKÐXÑXÔXÐXr8   rY   Ústarting_image_idÚstarting_annotation_idútuple[int, int]c	           
     ód   — |�t          | ||¬¦  «         |�t          | |||||||¬¦  «        S ||fS )u  
        Exports the dataset to COCO format. This method saves the
        images and their corresponding annotations in COCO format.

        !!! tip

            The format of the mask is determined automatically based on its structure:

            - If a mask contains multiple disconnected components or holes, it will be
            saved using the Run-Length Encoding (RLE) format for efficient storage and
            processing.
            - If a mask consists of a single, contiguous region without any holes, it
            will be encoded as a polygon, preserving the outline of the object.

            This automatic selection ensures that the masks are stored in the most
            appropriate and space-efficient format, complying with COCO dataset
            standards.

        Args:
            images_directory_path: The path to the directory
                where the images should be saved.
                If not provided, images will not be saved.
            annotations_path: The path to COCO annotation file.
            min_image_area_percentage: The minimum percentage of
                detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            max_image_area_percentage: The maximum percentage of
                detection area relative to
                the image area for a detection to be included.
                Argument is used only for segmentation datasets.
            approximation_percentage: The percentage of polygon points
                to be removed from the input polygon,
                in the range [0, 1). This is useful for simplifying the annotations.
                Argument is used only for segmentation datasets.
            starting_image_id: First image id to assign in the exported file.
                Defaults to ``1``. Override when exporting multiple splits into
                a coordinated COCO collection so ids remain unique across the
                set (see example below).
            starting_annotation_id: First annotation id to assign in the
                exported file. Defaults to ``1``. Override for the same
                multi-split reason as ``starting_image_id``.
            show_progress: If True, display a progress bar during saving.

        Returns:
            A ``(next_image_id, next_annotation_id)`` tuple containing the
            first unused ids after this export. Feed them straight back into
            ``starting_image_id`` and ``starting_annotation_id`` on the next
            split so ids stay globally unique. When ``annotations_path`` is
            ``None`` (images-only export) the starting ids are returned
            unchanged so chaining still composes.

        Example:
            ```python
            # Exporting train, valid, and test splits with non-colliding ids
            # so the three annotation files can later be merged into one COCO.
            next_image_id, next_annotation_id = train_ds.as_coco(
                images_directory_path="out/train/images",
                annotations_path="out/train/annotations.json",
            )
            next_image_id, next_annotation_id = valid_ds.as_coco(
                images_directory_path="out/valid/images",
                annotations_path="out/valid/annotations.json",
                starting_image_id=next_image_id,
                starting_annotation_id=next_annotation_id,
            )
            _, _ = test_ds.as_coco(
                images_directory_path="out/test/images",
                annotations_path="out/test/annotations.json",
                starting_image_id=next_image_id,
                starting_annotation_id=next_annotation_id,
            )  # return value not needed â€” no further split
            ```
        Nrä   )r¯   Úannotation_pathrÓ   rÔ   rÕ   r  r  rÖ   )r!   r   )	r5   rÐ   rú   rÓ   rÔ   rÕ   r  r  rÖ   s	            r6   Úas_cocozDetectionDataset.as_coco§  sp   € ðj !Ð,ÝØØ&;Ø+ðñ ô ð ð
 Ð'Ý(ØØ 0Ø*CØ*CØ)AØ"3Ø'=Ø+ð	ñ 	ô 	ð 	ð !Ð"8Ð8Ð8r8   )rJ   rK   rL   rM   r   rN   r/   rO   ©rT   rq   r/   rr   rC   )r‚   r0   r/   rƒ   )r/   rŠ   ©r�   r‘   r/   r?   rD   )r:   r;   r<   r=   r>   r?   r/   r˜   )r¬   r­   r/   rI   )NNrÎ   rÏ   rÎ   F)rÐ   rÑ   rÒ   rÑ   rÓ   r;   rÔ   r;   rÕ   r;   rÖ   r?   r/   rO   )FF)
rÐ   rq   rÒ   rq   ræ   r?   rÖ   r?   r/   rI   )FFF)rÐ   rq   rÒ   rq   ré   rq   ræ   r?   rê   r?   rÖ   r?   r/   rI   )NNNrÎ   rÏ   rÎ   FF)rÐ   rÑ   rÒ   rÑ   ré   rÑ   rÓ   r;   rÔ   r;   rÕ   r;   rê   r?   rÖ   r?   r/   rO   ©F)rÐ   rq   rÒ   rq   ræ   r?   r/   rI   )NN)rÐ   rÑ   rÒ   rÑ   r/   rO   )rÐ   rq   rú   rq   rÖ   r?   r/   rI   )NNF)rÐ   rÑ   rú   rÑ   rÖ   r?   r/   rO   )rÐ   rq   rú   rq   ræ   r?   rÖ   r?   rÿ   r?   r/   rI   )NNrÎ   rÏ   rÎ   rY   rY   F)rÐ   rÑ   rú   rÑ   rÓ   r;   rÔ   r;   rÕ   r;   r  r0   r  r0   rÖ   r?   r/   r  )rE   rF   rG   Ú__doc__rp   r}   r7   rˆ   r�   r—   rB   ÚclassmethodrÍ   rå   rè   rì   rõ   r÷   rù   rü   rþ   r  r  r3   r8   r6   rI   rI   J   sÚ  € € € € € ðð ð&7ð 7ð 7ð 7ðr2ð 2ð 2ð 2ðDð Dð Dð Dð	-ð 	-ð 	-ð 	-ð	0ð 	0ð 	0ð 	0ðð ð ð ð0 !Ø#'Øð	F+ð F+ð F+ð F+ð F+ðP ðdð dð dñ „[ðdðP -1Ø15Ø+.Ø+.Ø*-Ø#ðEð Eð Eð Eð EðN ð
 "Ø#ð7
ð 7
ð 7
ð 7
ñ „[ð7
ðr ð "ØØ#ð@
ð @
ð @
ð @
ñ „[ð@
ðH -1Ø15Ø%)Ø+.Ø+.Ø*-ØØ#ð`Pð `Pð `Pð `Pð `PðD ð
 "ð	8
ð 8
ð 8
ð 8
ñ „[ð8
ðx -1Ø15ð*ð *ð *ð *ð *ðX ð
 $ð	4
ð 4
ð 4
ð 4
ñ „[ð4
ðp -1Ø'+Ø#ð	)ð )ð )ð )ð )ðV ð
 "Ø#ð7Yð !ð7Yð 7Yð 7Yð 7Yð 7Yñ „[ð7Yðv -1Ø'+Ø+.Ø+.Ø*-Ø!"Ø&'Ø#ðf9ð f9ð f9ð f9ð f9ð f9ð f9r8   rI   c                  óz   — e Zd ZdZd)d
„Zd*d„Zd+d„Zd,d„Zd-d„Zd.d„Z		 	 	 d/d0d#„Z
	 d1d2d'„Ze	 d1d3d(„¦   «         ZdS )4ÚClassificationDatasetag  
    Contains information about a classification dataset, handles lazy image
    loading, dataset splitting.

    Attributes:
        classes: List containing dataset class names.
        images:
            List of image paths or dictionary mapping image name to image data.
        annotations: Dictionary mapping
            image name to annotations.
    rJ   rK   rL   rM   r   údict[str, Classifications]r/   rO   c                ó@  — || _         t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚|| _        t	          t
                               |¦  «        ¦  «        | _        i | _        t          |t
          ¦  «        r|| _        t          d¦  «         d S d S )NrQ   zžPassing a `Dict[str, np.ndarray]` into `ClassificationDataset` is deprecated and will be removed in a future release. Use a list of paths `List[str]` instead.)rJ   r[   r\   r   rf   rg   rh   ri   rj   rk   r$   )r5   rJ   rL   r   s       r6   rp   zClassificationDataset.__init__  s®   € ð ˆŒåˆv‰;Œ;�#˜kÑ*Ô*Ò*Ð*ÝØQñô ð ð 'ˆÔõ  ¥§¢¨fÑ 5Ô 5Ñ6Ô6ˆÔàCEˆÔÝ�f�dÑ#Ô#ð 	Ø%+ˆDÔ"Ýð7ñô ð ð ð ð	ð 	r8   rT   rq   rr   c                óÎ   — | j         r| j         |         S t          j        |¦  «        }|€t          d|› �¦  «        ‚t	          t
          j        t          j                 |¦  «        S rt   ru   r{   s      r6   r}   z ClassificationDataset._get_image8  r~   r8   r0   c                óR   — t          | j        ¦  «        pt          | j        ¦  «        S r2   r€   r4   s    r6   r7   zClassificationDataset.__len__A  r�   r8   r‚   ú2tuple[str, npt.NDArray[np.uint8], Classifications]c                ój   — | j         |         }|                      |¦  «        }| j        |         }|||fS r…   r†   r‡   s        r6   rˆ   z!ClassificationDataset.__getitem__D  r‰   r8   ú<Iterator[tuple[str, npt.NDArray[np.uint8], Classifications]]c              #  ón   K  — t          t          | ¦  «        ¦  «        D ]}| |         \  }}}|||fV — ŒdS rŒ   r�   r‡   s        r6   r�   zClassificationDataset.__iter__O  sU   è è € õ •s˜4‘y”yÑ!Ô!ð 	0ð 	0ˆAØ,0°¬GÑ)ˆJ˜˜zØ˜e ZÐ/Ð/Ð/Ð/Ð/ð	0ð 	0r8   r�   r‘   r?   c                óz  — t          |t          ¦  «        sdS | j        |j        k    rdS | j        |j        k    rdS | j        s|j        r_t          j        t          | j                             ¦   «         ¦  «        t          |j                             ¦   «         ¦  «        ¦  «        sdS | j	        |j	        k    rdS dS r“   )
rk   r  rJ   ri   rj   r^   r”   rf   r•   r   r–   s     r6   r—   zClassificationDataset.__eq__\  sÃ   € Ý˜%Õ!6Ñ7Ô7ð 	Ø�5àŒ<˜5œ=Ò(Ð(Ø�5àÔ˜uÔ0Ò0Ð0Ø�5àÔ!ð 	 UÔ%<ð 	Ý”>Ý�TÔ+×2Ò2Ñ4Ô4Ñ5Ô5Ý�UÔ,×3Ò3Ñ5Ô5Ñ6Ô6ñô ð ð �uàÔ˜uÔ0Ò0Ð0Ø�5àˆtr8   r9   NTr:   r;   r<   r=   r>   ú3tuple[ClassificationDataset, ClassificationDataset]c                ó&  ‡ — t          ‰ j        |||¬¦  «        \  }}‰ j        rˆ fd„|D ¦   «         }ˆ fd„|D ¦   «         }n|}|}ˆ fd„|D ¦   «         }ˆ fd„|D ¦   «         }	t          ‰ j        ||¬¦  «        }
t          ‰ j        ||	¬¦  «        }|
|fS )a"  
        Splits the dataset into two parts (training and testing)
            using the provided split_ratio.

        Args:
            split_ratio: The ratio of the training
                set to the entire dataset.
            random_state: The seed for the
                random number generator. This is used for reproducibility.
            shuffle: Whether to shuffle the data before splitting.

        Returns:
            A tuple containing
            the training and testing datasets.

        Examples:
            ```pycon
            >>> import numpy as np
            >>> import supervision as sv
            >>> cd = sv.ClassificationDataset(
            ...     classes=['cat', 'dog'],
            ...     images={
            ...         'img1.jpg': np.zeros((100, 100, 3), dtype=np.uint8),
            ...         'img2.jpg': np.zeros((100, 100, 3), dtype=np.uint8),
            ...     },
            ...     annotations={
            ...         'img1.jpg': sv.Classifications(class_id=np.array([0])),
            ...         'img2.jpg': sv.Classifications(class_id=np.array([1])),
            ...     }
            ... )
            >>> train_cd, test_cd = cd.split(split_ratio=0.5, random_state=42)
            >>> len(train_cd), len(test_cd)
            (1, 1)

            ```
        rš   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r¤   r�   s     €r6   rV   z/ClassificationDataset.split.<locals>.<dictcomp>¦  s#   ø€ ÐVÐVÐVÀ$˜4 Ô!7¸Ô!=ÐVÐVÐVr8   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r¤   r�   s     €r6   rV   z/ClassificationDataset.split.<locals>.<dictcomp>§  s#   ø€ ÐTÐTÐTÀ˜$ Ô 6°tÔ <ÐTÐTÐTr8   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r   r�   s     €r6   rV   z/ClassificationDataset.split.<locals>.<dictcomp>«  rŸ   r8   c                ó,   •— i | ]}|‰j         |         “ŒS r3   r   r�   s     €r6   rV   z/ClassificationDataset.split.<locals>.<dictcomp>¬  r¡   r8   r¢   )r"   ri   rj   r  rJ   )r5   r:   r<   r>   r¦   r§   Útrain_inputÚ
test_inputr¨   r©   rª   r«   s   `           r6   rB   zClassificationDataset.splitr  sú   ø€ õT #3ØÔ!Ø#Ø%Øð	#
ñ #
ô #
Ñˆ�Zð Ô!ð 	$ØVÐVÐVÐVÈ+ÐVÑVÔVˆKØTÐTÐTÐTÈÐTÑTÔTˆJˆJà%ˆKØ#ˆJØRÐRÐRÐRÀkÐRÑRÔRÐØPÐPÐPÐPÀZÐPÑPÔPÐå-Ø”LØØ)ð
ñ 
ô 
ˆõ
 -Ø”LØØ(ð
ñ 
ô 
ˆð ˜lÐ*Ð*r8   FÚroot_directory_pathrÖ   c                ól  ‡— i Š| j         D ]„}| j        |         }|j        €|j        d         n |                     d¦  «        d         d         }t
          j                             | j        |         t          |¦  «        j
        ¦  «        ‰|<   Œ…t          | j         ˆfd„d¬¦  «         t          j        |d¬¦  «         | j        D ]6}t          j        t
          j                             ||¦  «        d¬¦  «         Œ7t          | j         d	| ¬
¦  «        D ]�}t
          j                             |‰|         ¦  «        }|| j        v r!t          j        || j        |         ¦  «         ŒRt#          j        t&          j        ¦  «        5  t'          j        ||¦  «         ddd¦  «         n# 1 swxY w Y   ŒždS )aƒ  
        Saves the dataset as a multi-class folder structure.

        Images assigned to the same class must have unique basenames
        (case-insensitive). Conflicts are rejected before any files are written.
        Image files are copied unchanged; images held in memory are encoded to the
        format their name's extension selects.

        Args:
            root_directory_path: The path to the directory
                where the dataset will be saved.
            show_progress: If True, display a progress bar during saving.

        Raises:
            ValueError: If two images would be saved to the same output path.
        Nr   rY   c                ó   •— ‰|          S r2   r3   )rž   Úoutput_pathss    €r6   rÜ   z;ClassificationDataset.as_folder_structure.<locals>.<lambda>Ü  s   ø€ ˜\¨$Ô/€ r8   zclassification imagerÞ   T)Úexist_okzSaving classification images)ÚdescÚdisable)ri   r   Ú
confidencer`   Ú	get_top_kÚosrž   ÚjoinrJ   r   rÚ   r   Úmakedirsr   rj   rv   ÚimwriteÚ
contextlibÚsuppressÚshutilÚSameFileErrorÚcopyfile)	r5   r   rÖ   rT   rU   r`   Ú
class_nameÚimage_save_pathr#  s	           @r6   Úas_folder_structurez)ClassificationDataset.as_folder_structure»  s   ø€ ð& ˆØÔ*ð 		ð 		ˆJØÔ)¨*Ô5ˆJð Ô(Ð0ð Ô# AÔ&Ð&à×)Ò)¨!Ñ,Ô,¨QÔ/°Ô2ð õ
 (*¤w§|¢|Ø”˜XÔ&­¨ZÑ(8Ô(8Ô(=ñ(ô (ˆL˜Ñ$Ð$õ 	%ØÔ(Ø/Ð/Ð/Ð/Ø.ð	
ñ 	
ô 	
ð 	
õ
 	ŒÐ'°$Ð7Ñ7Ô7Ð7àœ,ð 	Vð 	VˆJÝŒK�œŸšÐ%8¸*ÑEÔEÐPTÐUÑUÔUÐUÐUåØÔØ/Ø%Ð%ð
ñ 
ô 
ð 	=ð 	=ˆJõ
 !œgŸlšlØ# \°*Ô%=ñô ˆOð ˜TÔ3Ð3Ð3Ý”˜O¨TÔ-CÀJÔ-OÑPÔPÐPØõ Ô$¥VÔ%9Ñ:Ô:ð =ð =Ý” 
¨OÑ<Ô<Ð<ð=ð =ð =ñ =ô =ð =ð =ð =ð =ð =ð =øøøð =ð =ð =ð =øð	=ð 	=s   ÆF(Æ(F,	Æ/F,	c                ó¤  — t          |¦  «        }t          d„ |                     ¦   «         D ¦   «         ¦  «        }g }i }t          t	          |t          |¦  «        d| ¬¦  «        ¦  «        D ]Ö\  }}||z  }	t          |	                     ¦   «         d„ ¬¦  «        D ]§}
|
j                             d¦  «        s|
                     ¦   «         sŒ1|
j	         
                    ¦   «         t          vrŒR|                     t          |
¦  «        ¦  «         t          t          j        |g¦  «        ¬¦  «        |t          |
¦  «        <   Œ¨Œ× | |||¬¦  «        S )	a  
        Load data from a multiclass folder structure into a ClassificationDataset.

        Args:
            root_directory_path: The path to the dataset directory. Hidden
                entries, root-level files, nested directories, and files whose
                suffix is not a supported image extension are ignored.
            show_progress: If True, display a progress bar during loading.

        Returns:
            The dataset.

        Examples:
            ```python
            import roboflow
            from roboflow import Roboflow
            import supervision as sv

            roboflow.login()
            rf = Roboflow()

            project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
            dataset = project.version(PROJECT_VERSION).download("folder")

            cd = sv.ClassificationDataset.from_folder_structure(
                root_directory_path=f"{dataset.location}/train"
                # pass show_progress=True to enable a tqdm progress bar
            )
            ```
        c                óx   — h | ]7}|                      ¦   «         ¯|j                             d ¦  «        °0|j        ’Œ8S )rW   )Úis_dirrÚ   Ú
startswith)rS   Úentrys     r6   ú	<setcomp>z>ClassificationDataset.from_folder_structure.<locals>.<setcomp>  sR   € ð ð ð àØ—<’<‘>”>ðð +0¬*×*?Ò*?ÀÑ*DÔ*DðØ”
ðð ð r8   zLoading classification dataset)Útotalr%  r&  c                ó   — | j         S r2   )rÚ   )rž   s    r6   rÜ   z=ClassificationDataset.from_folder_structure.<locals>.<lambda>.  s   € ¸D¼I€ r8   )rß   rW   )r`   r¢   )r   ÚsortedÚiterdirÚ	enumerater   rd   rÚ   r8  Úis_fileÚsuffixÚlowerÚ_IMAGE_FILE_EXTENSIONSÚappendrq   r   r^   r_   )rÅ   r   rÖ   Úroot_directoryrJ   ri   r   r`   r2  Úclass_directoryrT   s              r6   Úfrom_folder_structurez+ClassificationDataset.from_folder_structureõ  sœ  € õD Ð1Ñ2Ô2ˆÝðð à+×3Ò3Ñ5Ô5ðñ ô ñ
ô 
ˆð ˆØˆå$-ÝØÝ˜'‘l”lØ5Ø)Ð)ð	ñ ô ñ%
ô %
ð 	ð 	Ñ ˆH�jð -¨zÑ9ˆOå$Ø×'Ò'Ñ)Ô)Ð/EÐ/Eðñ ô ð 
ð 
�
ð ”?×-Ò-¨cÑ2Ô2ð ¸*×:LÒ:LÑ:NÔ:Nð ØØÔ$×*Ò*Ñ,Ô,Õ4JÐJÐJØØ×"Ò"¥3 z¡?¤?Ñ3Ô3Ð3Ý/>ÝœX x jÑ1Ô1ð0ñ 0ô 0��C 
™OœOÑ,Ð,ð
ð ˆsØØØ#ð
ñ 
ô 
ð 	
r8   )rJ   rK   rL   rM   r   r  r/   rO   r  rC   )r‚   r0   r/   r  )r/   r  r	  rD   )r:   r;   r<   r=   r>   r?   r/   r  r
  )r   rq   rÖ   r?   r/   rO   )r   rq   rÖ   r?   r/   r  )rE   rF   rG   r  rp   r}   r7   rˆ   r�   r—   rB   r4  r  rG  r3   r8   r6   r  r    s  € € € € € ð
ð 
ðð ð ð ð42ð 2ð 2ð 2ðDð Dð Dð Dð	-ð 	-ð 	-ð 	-ð0ð 0ð 0ð 0ðð ð ð ð0 !Ø#'Øð	G+ð G+ð G+ð G+ð G+ðT ?Dð8=ð 8=ð 8=ð 8=ð 8=ðt à=BðG
ð G
ð G
ð G
ñ „[ðG
ð G
ð G
r8   r  )CÚ
__future__r   r-  r)  r/  Úabcr   r   Úcollections.abcr   Úcopyr	   Údataclassesr
   Ú	itertoolsr   Úpathlibr   Útypingr   Únumpyr^   Únumpy.typingrx   Ú	tqdm.autor   Úsupervisionr   rv   Úsupervision.classification.corer   Úsupervision.configr   Ú supervision.dataset.formats.cocor   r   Ú$supervision.dataset.formats.createmlr   r   Ú#supervision.dataset.formats.labelmer   r   Ú&supervision.dataset.formats.pascal_vocr   r   Ú supervision.dataset.formats.yolor   r   r   Úsupervision.dataset.utilsr   r   r   r    r!   r"   Úsupervision.detection.corer#   Úsupervision.utils.internalr$   Úsupervision.utils.iterablesr%   Ú	frozensetrC  r.   rI   r  r3   r8   r6   ú<module>r`     s;  ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø 	€	€	€	Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à #Ð #Ð #Ð #Ð #Ð #Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð 2Ð 1Ð 1Ð 1Ð 1Ð 1Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7à"˜Ø?Ð?Ð?ñô Ð ð
ð ð ð ð �#ñ ô ð ðC9ð C9ð C9ð C9ð C9�{ñ C9ô C9ð C9ðL ðl
ð l
ð l
ð l
ð l
˜Kñ l
ô l
ñ „ðl
ð l
ð l
r8   