forked from open-mmlab/mmdetection
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverride_category.py
109 lines (96 loc) · 2.85 KB
/
override_category.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import mmengine
def parse_args():
parser = argparse.ArgumentParser(description='Override Category')
parser.add_argument('data_root')
return parser.parse_args()
def main():
args = parse_args()
ChessPieces = [{
'id': 1,
'name': ' ',
'supercategory': 'pieces'
}, {
'id': 2,
'name': 'black bishop',
'supercategory': 'pieces'
}, {
'id': 3,
'name': 'black king',
'supercategory': 'pieces'
}, {
'id': 4,
'name': 'black knight',
'supercategory': 'pieces'
}, {
'id': 5,
'name': 'black pawn',
'supercategory': 'pieces'
}, {
'id': 6,
'name': 'black queen',
'supercategory': 'pieces'
}, {
'id': 7,
'name': 'black rook',
'supercategory': 'pieces'
}, {
'id': 8,
'name': 'white bishop',
'supercategory': 'pieces'
}, {
'id': 9,
'name': 'white king',
'supercategory': 'pieces'
}, {
'id': 10,
'name': 'white knight',
'supercategory': 'pieces'
}, {
'id': 11,
'name': 'white pawn',
'supercategory': 'pieces'
}, {
'id': 12,
'name': 'white queen',
'supercategory': 'pieces'
}, {
'id': 13,
'name': 'white rook',
'supercategory': 'pieces'
}]
_data_root = args.data_root + 'ChessPieces/Chess Pieces.v23-raw.coco/'
json_data = mmengine.load(_data_root +
'valid/annotations_without_background.json')
json_data['categories'] = ChessPieces
mmengine.dump(json_data,
_data_root + 'valid/new_annotations_without_background.json')
CottontailRabbits = [{
'id': 1,
'name': 'rabbit',
'supercategory': 'Cottontail-Rabbit'
}]
_data_root = args.data_root + 'CottontailRabbits/'
json_data = mmengine.load(_data_root +
'valid/annotations_without_background.json')
json_data['categories'] = CottontailRabbits
mmengine.dump(json_data,
_data_root + 'valid/new_annotations_without_background.json')
NorthAmericaMushrooms = [{
'id': 1,
'name': 'flat mushroom',
'supercategory': 'mushroom'
}, {
'id': 2,
'name': 'yellow mushroom',
'supercategory': 'mushroom'
}]
_data_root = args.data_root + 'NorthAmericaMushrooms/North American Mushrooms.v1-416x416.coco/' # noqa
json_data = mmengine.load(_data_root +
'valid/annotations_without_background.json')
json_data['categories'] = NorthAmericaMushrooms
mmengine.dump(json_data,
_data_root + 'valid/new_annotations_without_background.json')
if __name__ == '__main__':
main()