import os import json import shutil from tqdm.notebook import tqdm lines = [] images = [] i = 1 for ann in tqdm(os.listdir("./data/key")[00:18]): 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("IdP-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], "./IdP-donut/train/" + images[i])