Skip to content
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

[Refactor] Refactor dataset metainfo to lowercase #362

Merged
merged 4 commits into from
Dec 27, 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
2 changes: 1 addition & 1 deletion configs/yolov5/voc/yolov5_s-v61_fast_1xb64-50e_voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
],
# Use ignore_keys to avoid judging metainfo is
# not equal in `ConcatDataset`.
ignore_keys='DATASET_TYPE'),
ignore_keys='dataset_type'),
collate_fn=dict(type='yolov5_collate'))

test_pipeline = [
Expand Down
4 changes: 2 additions & 2 deletions configs/yolov5/yolov5_s-v61_syncbn_fast_1xb4-300e_balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
train_num_workers = 2

metainfo = {
'CLASSES': ('balloon', ),
'PALETTE': [
'classes': ('balloon', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
2 changes: 1 addition & 1 deletion demo/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main():
files, source_type = get_file_list(args.img)

# get model class name
dataset_classes = model.dataset_meta.get('CLASSES')
dataset_classes = model.dataset_meta.get('classes')

# ready for labelme format if it is needed
to_label_format = LabelmeFormat(classes=dataset_classes)
Expand Down
1 change: 1 addition & 0 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Welcome to MMYOLO's documentation!

notes/changelog.md
notes/faq.md
notes/compatibility.md

.. toctree::
:maxdepth: 2
Expand Down
11 changes: 11 additions & 0 deletions docs/en/notes/compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Compatibility of MMYOLO

## MMYOLO 0.3.0

To unify with other OpenMMLab repositories, change all keys of `METAINFO` in Dataset from upper case to lower case.

| Before v0.3.0 | after v0.3.0 |
| :-----------: | :----------: |
| CLASSES | classes |
| PALETTE | palette |
| DATASET_TYPE | dataset_type |
4 changes: 2 additions & 2 deletions docs/en/user_guides/yolov5_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ train_batch_size_per_gpu = 4
train_num_workers = 2

metainfo = {
'CLASSES': ('balloon', ),
'PALETTE': [
'classes': ('balloon', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
1 change: 1 addition & 0 deletions docs/zh_cn/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

notes/faq.md
notes/changelog.md
notes/compatibility.md

.. toctree::
:maxdepth: 2
Expand Down
11 changes: 11 additions & 0 deletions docs/zh_cn/notes/compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# MMYOLO 兼容性说明

## MMYOLO v0.3.0

为了和 OpenMMLab 其他仓库统一,将 Dataset 里 `METAINFO` 的所有键从大写改为小写。

| 在 v0.3.0 之前 | v0.3.0 及之后 |
| :------------: | :-----------: |
| CLASSES | classes |
| PALETTE | palette |
| DATASET_TYPE | dataset_type |
4 changes: 2 additions & 2 deletions docs/zh_cn/user_guides/custom_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ base_lr = _base_.base_lr / 8
class_name = ('cat', ) # 根据 class_with_id.txt 类别信息,设置 class_name
num_classes = len(class_name)
metainfo = dict(
CLASSES=class_name,
PALETTE=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
classes=class_name,
palette=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
)

train_cfg = dict(
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_cn/user_guides/yolov5_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ train_batch_size_per_gpu = 4
train_num_workers = 2

metainfo = {
'CLASSES': ('balloon', ),
'PALETTE': [
'classes': ('balloon', ),
'palette': [
(220, 20, 60),
]
}
Expand Down
15 changes: 9 additions & 6 deletions mmyolo/utils/boxam_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ def init_detector(
checkpoint_meta = checkpoint.get('meta', {})
# save the dataset_meta in the model for convenience
if 'dataset_meta' in checkpoint_meta:
RangeKing marked this conversation as resolved.
Show resolved Hide resolved
# mmdet 3.x
model.dataset_meta = checkpoint_meta['dataset_meta']
# mmdet 3.x, all keys should be lowercase
model.dataset_meta = {
k.lower(): v
for k, v in checkpoint_meta['dataset_meta'].items()
}
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}
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 Expand Up @@ -254,7 +257,7 @@ def __init__(self,
if self.is_need_grad:
self.cam.activations_and_grads.release()

self.classes = model.detector.dataset_meta['CLASSES']
self.classes = model.detector.dataset_meta['classes']
self.COLORS = np.random.uniform(0, 255, size=(len(self.classes), 3))

def switch_activations_and_grads(self, model) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
class_name = ('cat', ) # 根据 class_with_id.txt 类别信息,设置 class_name
num_classes = len(class_name)
metainfo = dict(
CLASSES=class_name,
PALETTE=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
classes=class_name,
palette=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
)

train_cfg = dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class_name = ('cat', ) # 根据 class_with_id.txt 类别信息,设置 class_name
num_classes = len(class_name)
metainfo = dict(
CLASSES=class_name,
PALETTE=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
classes=class_name,
palette=[(220, 20, 60)] # 画图时候的颜色,随便设置即可
)

train_cfg = dict(
Expand Down
10 changes: 5 additions & 5 deletions tools/analysis_tools/dataset_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def replace_pipeline_to_none(cfg):
# Drawing settings
fig_all_set = {
'figsize': [35, 18],
'fontsize': int(10 - 0.08 * len(dataset.metainfo['CLASSES'])),
'fontsize': int(10 - 0.08 * len(dataset.metainfo['classes'])),
'xticks_angle': 70,
'out_name': cfg.dataset_type
}
Expand All @@ -396,15 +396,15 @@ def replace_pipeline_to_none(cfg):

# Call the category name and save address
if args.class_name is None:
classes = dataset.metainfo['CLASSES']
classes = dataset.metainfo['classes']
classes_idx = [i for i in range(len(classes))]
fig_set = fig_all_set
elif args.class_name in dataset.metainfo['CLASSES']:
elif args.class_name in dataset.metainfo['classes']:
classes = [args.class_name]
classes_idx = [dataset.metainfo['CLASSES'].index(args.class_name)]
classes_idx = [dataset.metainfo['classes'].index(args.class_name)]
fig_set = fig_one_set
else:
data_classes = dataset.metainfo['CLASSES']
data_classes = dataset.metainfo['classes']
show_data_classes(data_classes)
raise RuntimeError(f'Expected args.class_name to be one of the list,'
f'but got "{args.class_name}"')
Expand Down