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