diff --git a/src/globox/annotation.py b/src/globox/annotation.py index b4c45d5..a60ce69 100644 --- a/src/globox/annotation.py +++ b/src/globox/annotation.py @@ -104,7 +104,7 @@ def from_txt( box_format: BoxFormat = BoxFormat.LTRB, relative: bool = False, image_size: Optional["tuple[int, int]"] = None, - separator: str = " ", + separator: Optional[str] = None, conf_last: bool = False, ) -> "Annotation": path = Path(file_path).expanduser().resolve() @@ -153,7 +153,7 @@ def _from_yolo( box_format=BoxFormat.XYWH, relative=True, image_size=image_size, - separator=" ", + separator=None, conf_last=conf_last, ) diff --git a/src/globox/annotationset.py b/src/globox/annotationset.py index 23ed1b4..80c1068 100644 --- a/src/globox/annotationset.py +++ b/src/globox/annotationset.py @@ -203,7 +203,7 @@ def from_txt( relative=False, file_extension: str = ".txt", image_extension: str = ".jpg", - separator: str = " ", + separator: Optional[str] = None, conf_last: bool = False, verbose: bool = False, ) -> "AnnotationSet": @@ -286,6 +286,7 @@ def _from_yolo( box_format=BoxFormat.XYWH, relative=True, image_extension=image_extension, + separator=None, conf_last=conf_last, verbose=verbose, ) diff --git a/src/globox/boundingbox.py b/src/globox/boundingbox.py index 5597e2f..e2778cd 100644 --- a/src/globox/boundingbox.py +++ b/src/globox/boundingbox.py @@ -336,7 +336,7 @@ def from_txt( box_format=BoxFormat.LTRB, relative=False, image_size: Optional["tuple[int, int]"] = None, - separator: str = " ", + separator: Optional[str] = None, conf_last: bool = False, ) -> "BoundingBox": values = string.strip().split(separator) @@ -377,7 +377,7 @@ def from_yolo( box_format=BoxFormat.XYWH, relative=True, image_size=image_size, - separator=" ", + separator=None, conf_last=conf_last, ) diff --git a/tests/test_bbox.py b/tests/test_bbox.py index 0761d57..a1fac40 100644 --- a/tests/test_bbox.py +++ b/tests/test_bbox.py @@ -169,6 +169,16 @@ def test_from_txt_conf_last(): assert box.confidence == 0.25 +def test_from_txt_tab_sep(): + line = "label\t10\t20\t30\t40\t0.25" + box = BoundingBox.from_txt(line, conf_last=True) + assert box.confidence == 0.25 + + line = "label 0.25 10 20 30 40" + box = BoundingBox.from_txt(line) + assert box.confidence == 0.25 + + def test_from_yolo_v5(): line = "label 0.25 0.25 0.5 0.5 0.25" bbox = BoundingBox.from_yolo_v5(line, image_size=(100, 100)) @@ -203,6 +213,23 @@ def test_from_yolo_v7(): assert isclose(bbox.confidence, 0.25) +def test_from_yolo_v7_tab_sep(): + line = "label 0.25\t0.25\t0.5\t0.5\t0.25" + bbox = BoundingBox.from_yolo_v7(line, image_size=(100, 100)) + + assert bbox.label == "label" + assert bbox.confidence == 0.25 + + (xmin, ymin, xmax, ymax) = bbox.ltrb + + assert isclose(xmin, 0.0) + assert isclose(ymin, 0.0) + assert isclose(xmax, 50.0) + assert isclose(ymax, 50.0) + + assert isclose(bbox.confidence, 0.25) + + def test_to_yolo_darknet(): bbox = BoundingBox( label="label", xmin=0.0, ymin=0.0, xmax=50.0, ymax=50.0, confidence=0.25