import os import json import shutil from tqdm.notebook import tqdm lines = [] images = [] i = 1 for ann in tqdm(os.listdir("./data/key")[0:90]): i += 1 if ann != ".ipynb_checkpoints": with open("./data/key/" + ann) as f: data = json.load(f) images.append(ann[:-4] + "jpg") line = {"gt_parse": data} lines.append(line) with open("idReverso-donut/train/metadata.jsonll", 'w') as f: for i, gt_parse in enumerate(lines): line = {"file_name": images[i], "ground_truth": json.dumps(gt_parse)} f.write(json.dumps(line) + "\n") shutil.copyfile("./data/img/" + images[i], "./idReverso-donut/train/" + images[i])