Skip to content

[Refactor] Refactor dataset metainfo to lowercase. #9469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2022
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
4 changes: 2 additions & 2 deletions configs/_base_/datasets/voc0712.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
times=3,
dataset=dict(
type='ConcatDataset',
# VOCDataset will add different `DATASET_TYPE` in dataset.metainfo,
# VOCDataset will add different `dataset_type` in dataset.metainfo,
# which will get error if using ConcatDataset. Adding
# `ignore_keys` can avoid this error.
ignore_keys=['DATASET_TYPE'],
ignore_keys=['dataset_type'],
datasets=[
dict(
type=dataset_type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_base_ = './faster-rcnn_r50-caffe_fpn_ms-1x_coco.py'
model = dict(roi_head=dict(bbox_head=dict(num_classes=3)))
metainfo = {
'CLASSES': ('person', 'bicycle', 'car'),
'PALETTE': [
'classes': ('person', 'bicycle', 'car'),
'palette': [
(220, 20, 60),
(119, 11, 32),
(0, 0, 142),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_base_ = './faster-rcnn_r50-caffe_fpn_ms-1x_coco.py'
model = dict(roi_head=dict(bbox_head=dict(num_classes=1)))
metainfo = {
'CLASSES': ('person', ),
'PALETTE': [
'classes': ('person', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
6 changes: 3 additions & 3 deletions configs/pascal_voc/faster-rcnn_r50_fpn_1x_voc0712-cocofmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
model = dict(roi_head=dict(bbox_head=dict(num_classes=20)))

METAINFO = {
'CLASSES':
'classes':
('aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'),
# PALETTE is a list of color tuples, which is used for visualization.
'PALETTE': [(106, 0, 228), (119, 11, 32), (165, 42, 42), (0, 0, 192),
# palette is a list of color tuples, which is used for visualization.
'palette': [(106, 0, 228), (119, 11, 32), (165, 42, 42), (0, 0, 192),
(197, 226, 255), (0, 60, 100), (0, 0, 142), (255, 77, 255),
(153, 69, 1), (120, 166, 157), (0, 182, 199), (0, 226, 252),
(182, 182, 255), (0, 0, 230), (220, 20, 60), (163, 255, 0),
Expand Down
4 changes: 2 additions & 2 deletions configs/pascal_voc/ssd300_voc0712.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
# so the actual epoch = 12 * 10 = 120.
times=10,
dataset=dict( # ConcatDataset
# VOCDataset will add different `DATASET_TYPE` in dataset.metainfo,
# VOCDataset will add different `dataset_type` in dataset.metainfo,
# which will get error if using ConcatDataset. Adding
# `ignore_keys` can avoid this error.
ignore_keys=['DATASET_TYPE'],
ignore_keys=['dataset_type'],
datasets=[
dict(
type=dataset_type,
Expand Down
4 changes: 2 additions & 2 deletions configs/pascal_voc/ssd512_voc0712.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
# so the actual epoch = 12 * 10 = 120.
times=10,
dataset=dict( # ConcatDataset
# VOCDataset will add different `DATASET_TYPE` in dataset.metainfo,
# VOCDataset will add different `dataset_type` in dataset.metainfo,
# which will get error if using ConcatDataset. Adding
# `ignore_keys` can avoid this error.
ignore_keys=['DATASET_TYPE'],
ignore_keys=['dataset_type'],
datasets=[
dict(
type=dataset_type,
Expand Down
18 changes: 9 additions & 9 deletions docs/en/advanced_guides/customize_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Here we give an example to show the above two steps, which uses a customized dat

There are two aspects involved in the modification of config file:

1. The `data` field. Specifically, you need to explicitly add the `metainfo=dict(CLASSES=classes)` fields in `train_dataloader.dataset`, `val_dataloader.dataset` and `test_dataloader.dataset` and `classes` must be a tuple type.
1. The `data` field. Specifically, you need to explicitly add the `metainfo=dict(classes=classes)` fields in `train_dataloader.dataset`, `val_dataloader.dataset` and `test_dataloader.dataset` and `classes` must be a tuple type.
2. The `num_classes` field in the `model` part. Explicitly over-write all the `num_classes` from default value (e.g. 80 in COCO) to your classes number.

In `configs/my_custom_config.py`:
Expand All @@ -81,7 +81,7 @@ train_dataloader = dict(
dataset=dict(
type=dataset_type,
# explicitly add your class names to the field `metainfo`
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='train/annotation_data',
data_prefix=dict(img='train/image_data')
Expand All @@ -95,7 +95,7 @@ val_dataloader = dict(
type=dataset_type,
test_mode=True,
# explicitly add your class names to the field `metainfo`
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='val/annotation_data',
data_prefix=dict(img='val/image_data')
Expand All @@ -109,7 +109,7 @@ test_dataloader = dict(
type=dataset_type,
test_mode=True,
# explicitly add your class names to the field `metainfo`
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='test/annotation_data',
data_prefix=dict(img='test/image_data')
Expand Down Expand Up @@ -273,8 +273,8 @@ from mmdet.registry import DATASETS
class MyDataset(BaseDetDataset):

METAINFO = {
'CLASSES': ('person', 'bicycle', 'car', 'motorcycle'),
'PALETTE': [(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230)]
'classes': ('person', 'bicycle', 'car', 'motorcycle'),
'palette': [(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230)]
}

def load_data_list(self, ann_file):
Expand Down Expand Up @@ -341,15 +341,15 @@ The dataset will filter out the ground truth boxes of other classes automaticall
classes = ('person', 'bicycle', 'car')
train_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
val_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
test_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/en/advanced_guides/customize_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ If the hook is already implemented in MMDectection, you can directly modify the

#### Example: `NumClassCheckHook`

We implement a customized hook named [NumClassCheckHook](../../../mmdet/engine/hooks/num_class_check_hook.py) to check whether the `num_classes` in head matches the length of `CLASSES` in `dataset`.
We implement a customized hook named [NumClassCheckHook](../../../mmdet/engine/hooks/num_class_check_hook.py) to check whether the `num_classes` in head matches the length of `classes` in the metainfo of `dataset`.

We set it in [default_runtime.py](../../../configs/_base_/default_runtime.py).

Expand Down
4 changes: 2 additions & 2 deletions docs/en/user_guides/train.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ model = dict(
# Modify dataset related settings
data_root = 'data/balloon/'
metainfo = {
'CLASSES': ('balloon', ),
'PALETTE': [
'classes': ('balloon', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
18 changes: 9 additions & 9 deletions docs/zh_cn/advanced_guides/customize_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ COCO 格式的 JSON 标注文件有如下必要的字段:

配置文件的修改涉及两个方面:

1. `dataloaer` 部分。需要在 `train_dataloader.dataset`、`val_dataloader.dataset` 和 `test_dataloader.dataset` 中添加 `metainfo=dict(CLASSES=classes)`, 其中 classes 必须是 tuple 类型。
1. `dataloaer` 部分。需要在 `train_dataloader.dataset`、`val_dataloader.dataset` 和 `test_dataloader.dataset` 中添加 `metainfo=dict(classes=classes)`, 其中 classes 必须是 tuple 类型。
2. `model` 部分中的 `num_classes`。需要将默认值(COCO 数据集中为 80)修改为自定义数据集中的类别数。

`configs/my_custom_config.py` 内容如下:
Expand All @@ -83,7 +83,7 @@ train_dataloader = dict(
dataset=dict(
type=dataset_type,
# 将类别名字添加至 `metainfo` 字段中
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='train/annotation_data',
data_prefix=dict(img='train/image_data')
Expand All @@ -97,7 +97,7 @@ val_dataloader = dict(
type=dataset_type,
test_mode=True,
# 将类别名字添加至 `metainfo` 字段中
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='val/annotation_data',
data_prefix=dict(img='val/image_data')
Expand All @@ -110,7 +110,7 @@ test_dataloader = dict(
type=dataset_type,
test_mode=True,
# 将类别名字添加至 `metainfo` 字段中
metainfo=dict(CLASSES=classes),
metainfo=dict(classes=classes),
data_root=data_root,
ann_file='test/annotation_data',
data_prefix=dict(img='test/image_data')
Expand Down Expand Up @@ -270,8 +270,8 @@ from mmdet.registry import DATASETS
class MyDataset(BaseDetDataset):

METAINFO = {
'CLASSES': ('person', 'bicycle', 'car', 'motorcycle'),
'PALETTE': [(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230)]
'classes': ('person', 'bicycle', 'car', 'motorcycle'),
'palette': [(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230)]
}

def load_data_list(self, ann_file):
Expand Down Expand Up @@ -335,15 +335,15 @@ MMEngine 也支持非常多的数据集包装器(wrapper)来混合数据集
classes = ('person', 'bicycle', 'car')
train_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
val_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
test_dataloader = dict(
dataset=dict(
metainfo=dict(CLASSES=classes))
metainfo=dict(classes=classes))
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/advanced_guides/customize_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ custom_hooks = [

#### 例子: `NumClassCheckHook`

我们实现了一个名为 [NumClassCheckHook](https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/engine/hooks/num_class_check_hook.py) 的自定义钩子来检查 `num_classes` 是否在 head 中和 `dataset` 中的 `CLASSES` 的长度相匹配。
我们实现了一个名为 [NumClassCheckHook](https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/engine/hooks/num_class_check_hook.py) 的自定义钩子来检查 `num_classes` 是否在 head 中和 `dataset` 中的 `classes` 的长度相匹配。

我们在 [default_runtime.py](https://github.com/open-mmlab/mmdetection/blob/dev-3.x/configs/_base_/default_runtime.py) 中设置它。

Expand Down
4 changes: 2 additions & 2 deletions docs/zh_cn/user_guides/train.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ model = dict(
# 修改数据集相关配置
data_root = 'data/balloon/'
metainfo = {
'CLASSES': ('balloon', ),
'PALETTE': [
'classes': ('balloon', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
10 changes: 7 additions & 3 deletions mmdet/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ def init_detector(
elif 'CLASSES' in checkpoint_meta:
# < mmdet 3.x
classes = checkpoint_meta['CLASSES']
model.dataset_meta = {'CLASSES': classes, 'PALETTE': palette}
model.dataset_meta = {'classes': classes, 'palette': palette}
elif 'classes' in checkpoint_meta:
# < mmdet 3.x
classes = checkpoint_meta['classes']
model.dataset_meta = {'classes': classes, 'palette': palette}
else:
warnings.simplefilter('once')
warnings.warn(
'dataset_meta or class names are not saved in the '
'checkpoint\'s meta data, use COCO classes by default.')
model.dataset_meta = {
'CLASSES': get_classes('coco'),
'PALETTE': palette
'classes': get_classes('coco'),
'palette': palette
}

model.cfg = config # save the config in the model for convenience
Expand Down
4 changes: 2 additions & 2 deletions mmdet/datasets/cityscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class CityscapesDataset(CocoDataset):
"""Dataset for Cityscapes."""

METAINFO = {
'CLASSES': ('person', 'rider', 'car', 'truck', 'bus', 'train',
'classes': ('person', 'rider', 'car', 'truck', 'bus', 'train',
'motorcycle', 'bicycle'),
'PALETTE': [(220, 20, 60), (255, 0, 0), (0, 0, 142), (0, 0, 70),
'palette': [(220, 20, 60), (255, 0, 0), (0, 0, 142), (0, 0, 70),
(0, 60, 100), (0, 80, 100), (0, 0, 230), (119, 11, 32)]
}

Expand Down
10 changes: 5 additions & 5 deletions mmdet/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CocoDataset(BaseDetDataset):
"""Dataset for COCO."""

METAINFO = {
'CLASSES':
'classes':
('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep',
Expand All @@ -27,8 +27,8 @@ class CocoDataset(BaseDetDataset):
'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase',
'scissors', 'teddy bear', 'hair drier', 'toothbrush'),
# PALETTE is a list of color tuples, which is used for visualization.
'PALETTE':
# palette is a list of color tuples, which is used for visualization.
'palette':
[(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230), (106, 0, 228),
(0, 60, 100), (0, 80, 100), (0, 0, 70), (0, 0, 192), (250, 170, 30),
(100, 170, 30), (220, 220, 0), (175, 116, 175), (250, 0, 30),
Expand Down Expand Up @@ -63,9 +63,9 @@ def load_data_list(self) -> List[dict]:
with self.file_client.get_local_path(self.ann_file) as local_path:
self.coco = self.COCOAPI(local_path)
# The order of returned `cat_ids` will not
# change with the order of the CLASSES
# change with the order of the `classes`
self.cat_ids = self.coco.get_cat_ids(
cat_names=self.metainfo['CLASSES'])
cat_names=self.metainfo['classes'])
self.cat2label = {cat_id: i for i, cat_id in enumerate(self.cat_ids)}
self.cat_img_map = copy.deepcopy(self.coco.cat_img_map)

Expand Down
8 changes: 4 additions & 4 deletions mmdet/datasets/coco_panoptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CocoPanopticDataset(CocoDataset):
"""

METAINFO = {
'CLASSES':
'classes':
('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep',
Expand All @@ -92,7 +92,7 @@ class CocoPanopticDataset(CocoDataset):
'pavement-merged', 'mountain-merged', 'grass-merged', 'dirt-merged',
'paper-merged', 'food-other-merged', 'building-other-merged',
'rock-merged', 'wall-other-merged', 'rug-merged'),
'THING_CLASSES':
'thing_classes':
('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep',
Expand All @@ -106,7 +106,7 @@ class CocoPanopticDataset(CocoDataset):
'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase',
'scissors', 'teddy bear', 'hair drier', 'toothbrush'),
'STUFF_CLASSES':
'stuff_classes':
('banner', 'blanket', 'bridge', 'cardboard', 'counter', 'curtain',
'door-stuff', 'floor-wood', 'flower', 'fruit', 'gravel', 'house',
'light', 'mirror-stuff', 'net', 'pillow', 'platform', 'playingfield',
Expand All @@ -118,7 +118,7 @@ class CocoPanopticDataset(CocoDataset):
'pavement-merged', 'mountain-merged', 'grass-merged', 'dirt-merged',
'paper-merged', 'food-other-merged', 'building-other-merged',
'rock-merged', 'wall-other-merged', 'rug-merged'),
'PALETTE':
'palette':
[(220, 20, 60), (119, 11, 32), (0, 0, 142), (0, 0, 230), (106, 0, 228),
(0, 60, 100), (0, 80, 100), (0, 0, 70), (0, 0, 192), (250, 170, 30),
(100, 170, 30), (220, 220, 0), (175, 116, 175), (250, 0, 30),
Expand Down
10 changes: 5 additions & 5 deletions mmdet/datasets/crowdhuman.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CrowdHumanDataset(BaseDetDataset):
"""

METAINFO = {
'CLASSES': ('person', ),
# PALETTE is a list of color tuples, which is used for visualization.
'PALETTE': [(220, 20, 60)]
'classes': ('person', ),
# palette is a list of color tuples, which is used for visualization.
'palette': [(220, 20, 60)]
}

def __init__(self, data_root, ann_file, extra_ann_file=None, **kwargs):
Expand Down Expand Up @@ -122,11 +122,11 @@ def parse_data_info(self, raw_data_info: dict) -> Union[dict, List[dict]]:
instances = []
for i, ann in enumerate(raw_data_info['gtboxes']):
instance = {}
if ann['tag'] not in self.metainfo['CLASSES']:
if ann['tag'] not in self.metainfo['classes']:
instance['bbox_label'] = -1
instance['ignore_flag'] = 1
else:
instance['bbox_label'] = self.metainfo['CLASSES'].index(
instance['bbox_label'] = self.metainfo['classes'].index(
ann['tag'])
instance['ignore_flag'] = 0
if 'extra' in ann:
Expand Down
6 changes: 3 additions & 3 deletions mmdet/datasets/deepfashion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class DeepFashionDataset(CocoDataset):
"""Dataset for DeepFashion."""

METAINFO = {
'CLASSES': ('top', 'skirt', 'leggings', 'dress', 'outer', 'pants',
'classes': ('top', 'skirt', 'leggings', 'dress', 'outer', 'pants',
'bag', 'neckwear', 'headwear', 'eyeglass', 'belt',
'footwear', 'hair', 'skin', 'face'),
# PALETTE is a list of color tuples, which is used for visualization.
'PALETTE': [(0, 192, 64), (0, 64, 96), (128, 192, 192), (0, 64, 64),
# palette is a list of color tuples, which is used for visualization.
'palette': [(0, 192, 64), (0, 64, 96), (128, 192, 192), (0, 64, 64),
(0, 192, 224), (0, 192, 192), (128, 192, 64), (0, 192, 96),
(128, 32, 192), (0, 0, 224), (0, 0, 64), (0, 160, 192),
(128, 0, 96), (128, 0, 192), (0, 32, 192)]
Expand Down
Loading