Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # Modify COCO dataset annotation files.
  2. import glob
  3. import json
  4.  
  5. i = 0
  6. for file_path in glob.glob('/data/coco/Annotations_81/*/*.json'):
  7. dic = json.loads(open(file_path, 'r').read())
  8. ann1 = dic['annotation']
  9. ann2 = []
  10. for obj in ann1:
  11. if obj['category_id'] in [0, 1, 3, 6, 8]: # Accept only these object categories.
  12. if obj['category_id'] in [3, 6, 8]: # Set 'cars' objects to category 2.
  13. obj['category_id'] = 2
  14. ann2.append(obj)
  15. dic['annotation'] = ann2
  16. out_file = file_path.replace('_81', '')
  17. with open(out_file, 'w') as f:
  18. json.dump(dic, f)
  19. print('\r%d' % i, end='')
  20. i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement