{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"It takes a long time to load the 60,000+ json files containing all the training annotations for [Benetech - Making Graphs Accessible](https://www.kaggle.com/competitions/benetech-making-graphs-accessible/).\nThis notebook writes the contents of these files into a single one.","metadata":{}},{"cell_type":"code","source":"import os\nimport json\n\nimport numpy as np\nfrom PIL import Image\nfrom tqdm.auto import tqdm\n\ndef get_annotations():\n    path = f\"/kaggle/input/benetech-making-graphs-accessible/train/annotations\"\n    \n    data = {}\n    for filename in tqdm(os.listdir(path)):\n        with open(f\"{path}/{filename}\") as annotation_f:\n            annotation = json.load(annotation_f)\n        uid = filename.split(\".\")[0]\n        data[uid] = annotation\n        \n    return data\n\nannotations = get_annotations()\nwith open(\"train_annotations.json\", \"w\") as f:\n    json.dump(annotations, f)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-30T08:57:29.488527Z","iopub.execute_input":"2023-03-30T08:57:29.488973Z"},"trusted":true},"execution_count":null,"outputs":[]}]}