Skip to content

Commit ec443f0

Browse files
committed
minor fix
1 parent 178d41b commit ec443f0

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

configs/_base_/datasets/objects365v1_detection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
type='CocoMetric',
6060
ann_file=data_root + 'annotations/objects365_val.json',
6161
metric='bbox',
62+
sort_categories=True,
6263
format_only=False)
6364
test_evaluator = val_evaluator

mmdet/datasets/objects365.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,12 @@ def load_data_list(self) -> List[dict]:
106106
self.coco = self.COCOAPI(local_path)
107107

108108
# 'categories' list in objects365_train.json and objects365_val.json
109-
# is inconsistent, need sorted list(or dict) before get cat_ids.
109+
# is inconsistent, need sort list(or dict) before get cat_ids.
110110
cats = self.coco.cats
111111
sorted_cats = {i: cats[i] for i in sorted(cats)}
112-
print('----')
113-
print(cats)
114-
print('----')
115-
print(sorted_cats)
116112
self.coco.cats = sorted_cats
117113
categories = self.coco.dataset['categories']
118114
sorted_categories = sorted(categories, key=lambda i: i['id'])
119-
print('----')
120-
print(categories)
121-
print('----')
122-
print(sorted_categories)
123115
self.coco.dataset['categories'] = sorted_categories
124116
# The order of returned `cat_ids` will not
125117
# change with the order of the `classes`

mmdet/evaluation/metrics/coco_metric.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class CocoMetric(BaseMetric):
5959
names to disambiguate homonymous metrics of different evaluators.
6060
If prefix is not provided in the argument, self.default_prefix
6161
will be used instead. Defaults to None.
62+
sort_categories (bool): Whether sort categories in annotations. Only
63+
used for `Objects365V1Dataset`. Defaults to False.
6264
"""
6365
default_prefix: Optional[str] = 'coco'
6466

@@ -73,7 +75,8 @@ def __init__(self,
7375
outfile_prefix: Optional[str] = None,
7476
file_client_args: dict = dict(backend='disk'),
7577
collect_device: str = 'cpu',
76-
prefix: Optional[str] = None) -> None:
78+
prefix: Optional[str] = None,
79+
sort_categories: bool = False) -> None:
7780
super().__init__(collect_device=collect_device, prefix=prefix)
7881
# coco evaluation metrics
7982
self.metrics = metric if isinstance(metric, list) else [metric]
@@ -112,6 +115,17 @@ def __init__(self,
112115
if ann_file is not None:
113116
with self.file_client.get_local_path(ann_file) as local_path:
114117
self._coco_api = COCO(local_path)
118+
if sort_categories:
119+
# 'categories' list in objects365_train.json and
120+
# objects365_val.json is inconsistent, need sort
121+
# list(or dict) before get cat_ids.
122+
cats = self._coco_api.cats
123+
sorted_cats = {i: cats[i] for i in sorted(cats)}
124+
self._coco_api.cats = sorted_cats
125+
categories = self._coco_api.dataset['categories']
126+
sorted_categories = sorted(
127+
categories, key=lambda i: i['id'])
128+
self._coco_api.dataset['categories'] = sorted_categories
115129
else:
116130
self._coco_api = None
117131

0 commit comments

Comments
 (0)