diff --git a/src/supervision/dataset/formats/createml.py b/src/supervision/dataset/formats/createml.py index 84b939e9..4bcfac2f 100644 --- a/src/supervision/dataset/formats/createml.py +++ b/src/supervision/dataset/formats/createml.py @@ -77,21 +77,23 @@ def createml_annotations_to_detections( ``"label"``, or any coordinate sub-key), or if a coordinate value cannot be converted to float. - Examples: - ```python - import supervision as sv - from supervision.dataset.formats.createml import ( - createml_annotations_to_detections, - ) + Example: + ```pycon + >>> from supervision.dataset.formats.createml import ( + ... createml_annotations_to_detections, + ... ) + >>> annotations = [ + ... { + ... "label": "dog", + ... "coordinates": {"x": 50, "y": 50, "width": 20, "height": 20}, + ... } + ... ] + >>> detections = createml_annotations_to_detections(annotations, {"dog": 0}) + >>> detections.xyxy + array([[40., 40., 60., 60.]], dtype=float32) + >>> detections.class_id + array([0]) - annotations = [ - { - "label": "dog", - "coordinates": {"x": 50, "y": 50, "width": 20, "height": 20}, - } - ] - detections = createml_annotations_to_detections(annotations, {"dog": 0}) - # detections.xyxy → [[40, 40, 60, 60]] ``` """ if not image_annotations: @@ -240,20 +242,21 @@ def detections_to_createml_annotations( Raises: ValueError: If ``detections.class_id`` is ``None``. - Examples: - ```python - import numpy as np - import supervision as sv - from supervision.dataset.formats.createml import ( - detections_to_createml_annotations, - ) + Example: + ```pycon + >>> import numpy as np + >>> import supervision as sv + >>> from supervision.dataset.formats.createml import ( + ... detections_to_createml_annotations, + ... ) + >>> detections = sv.Detections( + ... xyxy=np.array([[40, 40, 60, 60]], dtype=np.float32), + ... class_id=np.array([0], dtype=int), + ... ) + >>> detections_to_createml_annotations(detections, classes=["dog"]) + [{'label': 'dog', 'coordinates': + {'x': 50.0, 'y': 50.0, 'width': 20.0, 'height': 20.0}}] - detections = sv.Detections( - xyxy=np.array([[40, 40, 60, 60]], dtype=np.float32), - class_id=np.array([0], dtype=int), - ) - detections_to_createml_annotations(detections, classes=["dog"]) - # [{"label": "dog", "coordinates": {"x": 50.0, "y": 50.0, ...}}] ``` """ class_ids = detections.class_id @@ -301,7 +304,7 @@ def save_createml_annotations( ValueError: If two image paths share the same basename and would map to the same CreateML ``image`` entry. - Examples: + Example: ```python import supervision as sv from supervision.dataset.formats.createml import save_createml_annotations