fix for unlabeled class (#5)
Browse files- cocostuff.py +18 -14
cocostuff.py
CHANGED
@@ -71,8 +71,20 @@ def _load_labels(labels_path: str) -> Dict[int, str]:
|
|
71 |
logger.info(f"Load labels from {labels_path}")
|
72 |
with open(labels_path, "r") as rf:
|
73 |
for line in rf:
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return label_id_to_label_name
|
77 |
|
78 |
|
@@ -244,12 +256,8 @@ class CocoStuffDataset(ds.GeneratorBasedBuilder):
|
|
244 |
img_anns = image_id_to_stuff_annotations[image_id]
|
245 |
bboxes = [list(map(int, ann["bbox"])) for ann in img_anns]
|
246 |
category_ids = [ann["category_id"] for ann in img_anns]
|
247 |
-
category_labels = list(
|
248 |
-
|
249 |
-
lambda cat_id: id_to_label.get(cat_id, f"unknown-{cat_id}"),
|
250 |
-
category_ids,
|
251 |
-
)
|
252 |
-
)
|
253 |
assert len(bboxes) == len(category_ids) == len(category_labels)
|
254 |
zip_it = zip(bboxes, category_ids, category_labels)
|
255 |
objects_example = [
|
@@ -313,12 +321,8 @@ class CocoStuffDataset(ds.GeneratorBasedBuilder):
|
|
313 |
img_anns = image_id_to_stuff_annotations[image_id]
|
314 |
bboxes = [list(map(int, ann["bbox"])) for ann in img_anns]
|
315 |
category_ids = [ann["category_id"] for ann in img_anns]
|
316 |
-
category_labels = list(
|
317 |
-
|
318 |
-
lambda cat_id: id_to_label.get(cat_id, f"unknown-{cat_id}"),
|
319 |
-
category_ids,
|
320 |
-
)
|
321 |
-
)
|
322 |
assert len(bboxes) == len(category_ids) == len(category_labels)
|
323 |
zip_it = zip(bboxes, category_ids, category_labels)
|
324 |
objects_example = [
|
|
|
71 |
logger.info(f"Load labels from {labels_path}")
|
72 |
with open(labels_path, "r") as rf:
|
73 |
for line in rf:
|
74 |
+
label_id_str, label_name = line.strip().split(": ")
|
75 |
+
label_id = int(label_id_str)
|
76 |
+
|
77 |
+
# correspondence between .png annotation & category_id · Issue #17 · nightrome/cocostuff https://github.com/nightrome/cocostuff/issues/17
|
78 |
+
# Label matching, 182 or 183 labels? · Issue #8 · nightrome/cocostuff https://github.com/nightrome/cocostuff/issues/8
|
79 |
+
if label_id == 0:
|
80 |
+
# for unlabeled class
|
81 |
+
assert label_name == "unlabeled", label_name
|
82 |
+
label_id_to_label_name[183] = label_name
|
83 |
+
else:
|
84 |
+
label_id_to_label_name[label_id] = label_name
|
85 |
+
|
86 |
+
assert len(label_id_to_label_name) == 183
|
87 |
+
|
88 |
return label_id_to_label_name
|
89 |
|
90 |
|
|
|
256 |
img_anns = image_id_to_stuff_annotations[image_id]
|
257 |
bboxes = [list(map(int, ann["bbox"])) for ann in img_anns]
|
258 |
category_ids = [ann["category_id"] for ann in img_anns]
|
259 |
+
category_labels = list(map(lambda cid: id_to_label[cid], category_ids))
|
260 |
+
|
|
|
|
|
|
|
|
|
261 |
assert len(bboxes) == len(category_ids) == len(category_labels)
|
262 |
zip_it = zip(bboxes, category_ids, category_labels)
|
263 |
objects_example = [
|
|
|
321 |
img_anns = image_id_to_stuff_annotations[image_id]
|
322 |
bboxes = [list(map(int, ann["bbox"])) for ann in img_anns]
|
323 |
category_ids = [ann["category_id"] for ann in img_anns]
|
324 |
+
category_labels = list(map(lambda cid: id_to_label[cid], category_ids))
|
325 |
+
|
|
|
|
|
|
|
|
|
326 |
assert len(bboxes) == len(category_ids) == len(category_labels)
|
327 |
zip_it = zip(bboxes, category_ids, category_labels)
|
328 |
objects_example = [
|