Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Modify COCO dataset annotation files.
- import glob
- import json
- i = 0
- for file_path in glob.glob('/data/coco/Annotations_81/*/*.json'):
- dic = json.loads(open(file_path, 'r').read())
- ann1 = dic['annotation']
- ann2 = []
- for obj in ann1:
- if obj['category_id'] in [0, 1, 3, 6, 8]: # Accept only these object categories.
- if obj['category_id'] in [3, 6, 8]: # Set 'cars' objects to category 2.
- obj['category_id'] = 2
- ann2.append(obj)
- dic['annotation'] = ann2
- out_file = file_path.replace('_81', '')
- with open(out_file, 'w') as f:
- json.dump(dic, f)
- print('\r%d' % i, end='')
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement