Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/labelformat/formats/yolov8.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_labels(self) -> Iterable[ImageInstanceSegmentation]:
)
continue
with label_path.open() as file:
label_data = [line.split() for line in file.readlines()]
label_data = [line.split() for line in file if line.strip()]

objects = []
for row in label_data:
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/formats/test_yolov8.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ def test_instance_segmentation__image_without_label_file(
] == expected


def test_yolov8_instance_segmentation_input__blank_lines(tmp_path: Path) -> None:
config_file = _make_dataset_with_background_image(
tmp_path=tmp_path, label_line="0 0.1 0.1 0.5 0.1 0.5 0.5\n\n \n"
)

labels = list(
YOLOv8InstanceSegmentationInput(
input_file=config_file, input_split="train"
).get_labels()
)

assert [(label.image.filename, len(label.objects)) for label in labels] == [
("labeled.jpg", 1)
]


def _make_dataset_with_background_image(tmp_path: Path, label_line: str) -> Path:
"""Create a YOLOv8 dataset where only labeled.jpg has a label file."""
images_dir = tmp_path / "images"
Expand Down
Loading