Skip to content

Commit

Permalink
Merge pull request #40 from laclouis5/txt-whitespace-separator
Browse files Browse the repository at this point in the history
  • Loading branch information
laclouis5 authored Sep 30, 2023
2 parents 0b3c176 + 74e92c1 commit 70a101e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/globox/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -153,7 +153,7 @@ def _from_yolo(
box_format=BoxFormat.XYWH,
relative=True,
image_size=image_size,
separator=" ",
separator=None,
conf_last=conf_last,
)

Expand Down
3 changes: 2 additions & 1 deletion src/globox/annotationset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions src/globox/boundingbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -377,7 +377,7 @@ def from_yolo(
box_format=BoxFormat.XYWH,
relative=True,
image_size=image_size,
separator=" ",
separator=None,
conf_last=conf_last,
)

Expand Down
27 changes: 27 additions & 0 deletions tests/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 70a101e

Please sign in to comment.