-
Notifications
You must be signed in to change notification settings - Fork 15
/
converter.py
30 lines (23 loc) · 842 Bytes
/
converter.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
import os
import json
from argparse import ArgumentParser as ArgParse
# Method to obtain json files with class information
def main(label):
output_path = label + '_withclasses.json'
out = open(output_path, 'w')
with open(label + '.json') as json_file, open(label + '_classes.txt') as txt:
for line_json, line_classes in zip(json_file, txt):
line_json = line_json.strip()
line_classes = line_classes.strip()
j_content = json.loads(line_json)
j_content['classes'] = line_classes
string = json.dumps(j_content)
string += '\n'
out.write(string)
if __name__ == '__main__':
ap = ArgParse()
ap.add_argument('--root', type=str, default='.')
args = ap.parse_args()
main(os.path.join(args.root, "label_data_0313"))
main(os.path.join(args.root, "label_data_0531"))
main(os.path.join(args.root, "label_data_0601"))