From f8005b268b86c661350feb818a87ea6768fb7cfd Mon Sep 17 00:00:00 2001 From: kirilllzaitsev Date: Sat, 29 Jul 2023 23:39:42 +0200 Subject: [PATCH] add docstrings --- supervision/dataset/formats/pascal_voc.py | 34 +++++++++++++++++++++-- test/dataset/formats/test_pascal_voc.py | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/supervision/dataset/formats/pascal_voc.py b/supervision/dataset/formats/pascal_voc.py index c325e80a..53834d34 100644 --- a/supervision/dataset/formats/pascal_voc.py +++ b/supervision/dataset/formats/pascal_voc.py @@ -172,7 +172,36 @@ def load_pascal_voc_annotations( return classes, images, annotations -def detections_from_xml_obj(root, classes, resolution_wh, force_masks=False): +def detections_from_xml_obj( + root: Element, classes: List[str], resolution_wh, force_masks: bool = False +) -> Tuple[Detections, List[str]]: + """ + Converts an XML object in Pascal VOC format to a Detections object. + Expected XML format: + + ... + + dog + + 48 + 240 + 195 + 371 + + + 48 + 240 + 195 + 240 + 195 + 371 + 48 + 371 + + + + + """ xyxy = [] class_names = [] masks = [] @@ -217,7 +246,8 @@ def detections_from_xml_obj(root, classes, resolution_wh, force_masks=False): return annotation, extended_classes -def parse_polygon_points(polygon: Element): +def parse_polygon_points(polygon: Element) -> List[List[int]]: + # Parses polygon points in format: ............... polygon_points = [] coords = polygon.findall(".//*") for i in range(0, len(coords), 2): diff --git a/test/dataset/formats/test_pascal_voc.py b/test/dataset/formats/test_pascal_voc.py index fa900f1c..d1f25bd7 100644 --- a/test/dataset/formats/test_pascal_voc.py +++ b/test/dataset/formats/test_pascal_voc.py @@ -97,7 +97,7 @@ def test_parse_polygon_points( "xml_string, classes, resolution_wh, force_masks, expected_result, exception", [ ( - """test.jpg100100test001010""", + """test001010""", ["test"], (100, 100), False,