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
6 changes: 0 additions & 6 deletions fastlabel/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def to_coco(
annotation_id = 0
image_index = 0
for task in tasks:
if task["height"] == 0 or task["width"] == 0:
continue

if is_video_project_type(project_type):
image_file_names = _export_image_files_for_video_task(
task, str((Path(output_dir) / "images").resolve())
Expand Down Expand Up @@ -726,9 +723,6 @@ def _truncate(n, decimals=0) -> float:
def to_pascalvoc(project_type: str, tasks: list, output_dir: str) -> list:
pascalvoc = []
for task in tasks:
if task["height"] == 0 or task["width"] == 0:
continue

if is_video_project_type(project_type):
image_file_names = _export_image_files_for_video_task(
task, str((Path(output_dir) / "images").resolve())
Expand Down
201 changes: 201 additions & 0 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
from fastlabel import converters


class TestToCoco:
"""Tests for to_coco converter function."""

def test_to_coco_with_zero_height_task(self, tmp_path):
"""Test that tasks with height=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 0,
"width": 100,
"annotations": [
{
"type": "bbox",
"value": "cat",
"points": [10, 10, 50, 50],
"color": "#FF0000",
}
],
},
{
"name": "image2.jpg",
"height": 100,
"width": 100,
"annotations": [
{
"type": "bbox",
"value": "cat",
"points": [10, 10, 50, 50],
"color": "#FF0000",
}
],
},
]

result = converters.to_coco(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result["images"]) == 2
assert result["images"][0]["height"] == 0
assert result["images"][1]["height"] == 100

def test_to_coco_with_zero_width_task(self, tmp_path):
"""Test that tasks with width=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 100,
"width": 0,
"annotations": [
{
"type": "bbox",
"value": "dog",
"points": [10, 10, 50, 50],
"color": "#00FF00",
}
],
},
]

result = converters.to_coco(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result["images"]) == 1
assert result["images"][0]["width"] == 0

def test_to_coco_with_zero_dimensions_task(self, tmp_path):
"""Test that tasks with both height=0 and width=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 0,
"width": 0,
"annotations": [
{
"type": "bbox",
"value": "bird",
"points": [10, 10, 50, 50],
"color": "#0000FF",
}
],
},
]

result = converters.to_coco(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result["images"]) == 1
assert result["images"][0]["height"] == 0
assert result["images"][0]["width"] == 0


class TestToPascalVoc:
"""Tests for to_pascalvoc converter function."""

def test_to_pascalvoc_with_zero_height_task(self, tmp_path):
"""Test that tasks with height=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 0,
"width": 100,
"annotations": [
{
"type": "bbox",
"value": "cat",
"points": [10, 10, 50, 50],
"attributes": [],
}
],
},
{
"name": "image2.jpg",
"height": 100,
"width": 100,
"annotations": [
{
"type": "bbox",
"value": "cat",
"points": [10, 10, 50, 50],
"attributes": [],
}
],
},
]

result = converters.to_pascalvoc(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result) == 2
assert result[0]["annotation"]["size"]["height"] == 0
assert result[1]["annotation"]["size"]["height"] == 100

def test_to_pascalvoc_with_zero_width_task(self, tmp_path):
"""Test that tasks with width=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 100,
"width": 0,
"annotations": [
{
"type": "bbox",
"value": "dog",
"points": [10, 10, 50, 50],
"attributes": [],
}
],
},
]

result = converters.to_pascalvoc(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result) == 1
assert result[0]["annotation"]["size"]["width"] == 0

def test_to_pascalvoc_with_zero_dimensions_task(self, tmp_path):
"""Test that tasks with both height=0 and width=0 are included in output."""
tasks = [
{
"name": "image1.jpg",
"height": 0,
"width": 0,
"annotations": [
{
"type": "bbox",
"value": "bird",
"points": [10, 10, 50, 50],
"attributes": [],
}
],
},
]

result = converters.to_pascalvoc(
project_type="image_bbox",
tasks=tasks,
output_dir=str(tmp_path),
)

assert len(result) == 1
assert result[0]["annotation"]["size"]["height"] == 0
assert result[0]["annotation"]["size"]["width"] == 0
Loading