Skip to content

Commit 52cacf3

Browse files
committed
More cleaning up and consistency across exporters, keep higher-bound estimation for two exporters for size
1 parent 8739124 commit 52cacf3

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

luxonis_ml/data/exporters/createml_exporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def _collect_bounding_box_annotations(
104104
per_image_anns: list[dict[str, Any]] = []
105105

106106
for row in group_df.iter_rows(named=True):
107-
ttype = row.get("task_type")
108-
ann_str = row.get("annotation")
109-
cname = row.get("class_name")
107+
ttype = row["task_type"]
108+
ann_str = row["annotation"]
109+
cname = row["class_name"]
110110

111111
if ttype != "boundingbox" or ann_str is None or not cname:
112112
continue

luxonis_ml/data/exporters/darknet_exporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def _collect_darknet_bounding_box_labels(
8080
label_lines: list[str] = []
8181

8282
for row in group_df.iter_rows(named=True):
83-
ttype = row.get("task_type")
84-
ann_str = row.get("annotation")
85-
cname = row.get("class_name")
83+
ttype = row["task_type"]
84+
ann_str = row["annotation"]
85+
cname = row["class_name"]
8686

8787
if ttype != "boundingbox" or ann_str is None:
8888
continue

luxonis_ml/data/exporters/segmentation_mask_directory_exporter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010
from PIL import Image
11-
from pycocotools import mask as maskUtils # <- use pycocotools
11+
from pycocotools import mask as maskUtils
1212

1313
from luxonis_ml.data.exporters.base_exporter import BaseExporter
1414
from luxonis_ml.data.exporters.exporter_utils import ExporterUtils, PreparedLDF
@@ -75,13 +75,13 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
7575
file_path = Path(str(file_name))
7676
split = ExporterUtils.split_of_group(prepared_ldf, group_id)
7777

78-
# Only segmentation rows (instance_id == -1)
78+
# Only semantic segmentation rows for the entire image (instance_id == -1)
7979
seg_rows = [
8080
row
8181
for row in entry.iter_rows(named=True)
82-
if row.get("task_type") == "segmentation"
83-
and row.get("instance_id") == -1
84-
and row.get("annotation")
82+
if row["task_type"] == "segmentation"
83+
and row["instance_id"] == -1
84+
and row["annotation"]
8585
]
8686
if not seg_rows:
8787
continue
@@ -106,11 +106,11 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
106106
combined: np.ndarray | None = None
107107

108108
for row in seg_rows:
109-
cname = str(row.get("class_name") or "")
109+
cname = str(row["class_name"] or "")
110110
if not cname:
111111
continue
112112

113-
ann = row.get("annotation")
113+
ann = row["annotation"]
114114
ann = json.loads(ann)
115115

116116
m = _decode_rle_with_pycoco(ann) # uint8 {0,1}

luxonis_ml/data/exporters/tensorflow_csv_exporter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
5656

5757
per_image_rows: list[dict[str, Any]] = []
5858
for row in group_df.iter_rows(named=True):
59-
if row.get("task_type") != "boundingbox":
59+
if row["task_type"] != "boundingbox":
6060
continue
61-
ann = row.get("annotation")
61+
ann = row["annotation"]
6262
ann = json.loads(ann)
63-
cname = row.get("class_name")
63+
cname = row["class_name"]
6464
if ann is None or not cname:
6565
continue
6666

@@ -90,6 +90,9 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
9090
if per_image_rows:
9191
rows_by_split[split_name].extend(per_image_rows)
9292

93+
# NOTE: We use a rough constant (64) to approximate the per-row CSV bytes that do NOT
94+
# depend on variable-length fields. Getting the true on-disk size here would require
95+
# serializing with csv.DictWriter using the exact dialect and encoding
9396
ann_size_est = sum(
9497
64 + len(r["class"]) + len(r["filename"])
9598
for r in per_image_rows

luxonis_ml/data/exporters/voc_exporter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
4747

4848
objects: list[dict[str, Any]] = []
4949
for row in group_df.iter_rows(named=True):
50-
if row.get("task_type") != "boundingbox":
50+
if row["task_type"] != "boundingbox":
5151
continue
52-
ann_str = row.get("annotation")
53-
cname = row.get("class_name")
52+
ann_str = row["annotation"]
53+
cname = row["class_name"]
5454
if not ann_str or not cname:
5555
continue
5656

@@ -63,11 +63,9 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
6363
xmin = int(round(xn * W))
6464
ymin = int(round(yn * H))
6565

66-
# widths/heights: round once (no double rounding)
6766
w_px = max(1, int(round(wn * W)))
6867
h_px = max(1, int(round(hn * H)))
6968

70-
# build EXCLUSIVE max from min + size
7169
xmax = xmin + w_px # exclusive right edge
7270
ymax = ymin + h_px # exclusive bottom edge
7371

@@ -214,7 +212,6 @@ def _build_voc_xml_string(
214212
SubElement(bb, "xmax").text = f"{xmax:.12f}"
215213
SubElement(bb, "ymax").text = f"{ymax:.12f}"
216214

217-
# pretty print with XML declaration
218215
xml_bytes = self._etree_to_pretty_bytes(ann)
219216
return xml_bytes.decode("utf-8")
220217

luxonis_ml/data/exporters/yolo_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def transform(self, prepared_ldf: PreparedLDF) -> None:
7474
)
7575
new_name = f"{idx}{file_path.suffix}"
7676

77-
label_lines: list[BBox] = []
77+
label_lines: list = []
7878

7979
for row in group_df.iter_rows(named=True):
8080
ttype = row["task_type"]

tests/test_data/test_parse_export_equivalence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def collect_classification_multiset(prepared_ldf: PreparedLDF):
246246
{"url": "D2_Tile.png-mask-semantic.zip", "types": ["segmentation"]},
247247
{
248248
"url": "COCO_people_subset.zip",
249-
"types": ["instance_segmentation", "boundingbox", "keypoints"],
249+
"types": ["instance_segmentation", "boundingbox"],
250250
},
251251
]
252252

0 commit comments

Comments
 (0)