You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gen_json.py 912 B

12345678910111213141516171819202122
  1. import json
  2. import os
  3. def dump_json_from_dict(structure, file_name):
  4. with open(file_name + '.json', 'w') as fp:
  5. json.dump(structure, fp)
  6. if __name__ == '__main__':
  7. # iterate over DIRECTORY
  8. DIRECTORY = os.path.dirname(os.path.realpath(__file__)) + "/original"
  9. PARENT_DIR = os.path.dirname(DIRECTORY)
  10. i = -1
  11. for filename in os.listdir(DIRECTORY):
  12. default_dict = {}
  13. default_dict.update(dataset='')
  14. default_dict.update(image=os.path.abspath(os.path.join(DIRECTORY, filename)))
  15. default_dict.update(label=['3', '2'])
  16. default_dict.update(_priority=[0.8, 0.3])
  17. default_dict.update(_embedding=os.path.abspath(os.path.join(PARENT_DIR, 'sample.bin')))
  18. default_dict.update(_processed_image=os.path.abspath(os.path.join(DIRECTORY, filename)))
  19. i = i + 1
  20. dump_json_from_dict(default_dict, PARENT_DIR + '/images/'+str(i))