{"cells":[{"cell_type":"markdown","metadata":{"id":"Cxi8K9mXwl5t"},"source":["# Convert Coco JSON Annotations to YOLO TXT Files\n","Use this notebook to try out importing, analyzing, and exporting datasets of image annotations. "]},{"cell_type":"code","execution_count":1,"metadata":{"id":"Bg_k6RQq-hGD","executionInfo":{"status":"ok","timestamp":1659249730835,"user_tz":-360,"elapsed":5225,"user":{"displayName":"Iftekharul Abedeen, 170042083","userId":"18230713862676727834"}}},"outputs":[],"source":["import logging\n","logging.getLogger().setLevel(logging.CRITICAL)\n","!pip install pylabel > /dev/null"]},{"cell_type":"code","execution_count":2,"metadata":{"id":"AYwWkeF4z1Sc","executionInfo":{"status":"ok","timestamp":1659249737474,"user_tz":-360,"elapsed":1787,"user":{"displayName":"Iftekharul Abedeen, 170042083","userId":"18230713862676727834"}}},"outputs":[],"source":["from pylabel import importer"]},{"cell_type":"markdown","metadata":{"id":"oQ_vZ8tb-hGE"},"source":["## Import coco annotations \n","First we will import annotations from the coco dataset, which are in coco json format. "]},{"cell_type":"code","execution_count":3,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":504},"id":"z82ThgC0-hGE","executionInfo":{"status":"ok","timestamp":1659249787827,"user_tz":-360,"elapsed":409,"user":{"displayName":"Iftekharul Abedeen, 170042083","userId":"18230713862676727834"}},"outputId":"649924da-ffd6-4cb7-998d-0ee238c411a8"},"outputs":[{"output_type":"execute_result","data":{"text/plain":[" img_folder img_filename img_path img_id img_width img_height \\\n","id \n","0 IMG0000025.jpg 1 2880 2304 \n","1 IMG0000044.jpg 2 2304 2880 \n","2 IMG0000100.jpg 3 2304 2880 \n","3 IMG0000155.jpg 4 2304 2880 \n","4 IMG0000156.jpg 5 2304 2880 \n","\n"," img_depth ann_segmented ann_bbox_xmin ann_bbox_ymin ... \\\n","id ... \n","0 1466.504519 2010.557108 ... \n","1 1426.511093 1072.013147 ... \n","2 683.437962 1038.882498 ... \n","3 491.753492 1043.615448 ... \n","4 647.940838 1090.944947 ... \n","\n"," ann_segmentation ann_iscrowd ann_pose \\\n","id \n","0 [[1466.504519309778, 2010.557107641742, 1515.7... 0 \n","1 [[1554.300739523418, 1076.746096959737, 1457.2... 0 \n","2 [[683.4379622021364, 1088.5784716516023, 685.8... 0 \n","3 [[572.2136400986032, 1043.6154478225144, 515.4... 0 \n","4 [[700.0032867707478, 1098.0443714050944, 657.4... 0 \n","\n"," ann_truncated ann_difficult cat_id cat_name cat_supercategory split \\\n","id \n","0 0 fractured \n","1 0 fractured \n","2 0 fractured \n","3 0 fractured \n","4 0 fractured \n","\n"," annotated \n","id \n","0 1 \n","1 1 \n","2 1 \n","3 1 \n","4 1 \n","\n","[5 rows x 25 columns]"],"text/html":["\n","
\n"," | img_folder | \n","img_filename | \n","img_path | \n","img_id | \n","img_width | \n","img_height | \n","img_depth | \n","ann_segmented | \n","ann_bbox_xmin | \n","ann_bbox_ymin | \n","... | \n","ann_segmentation | \n","ann_iscrowd | \n","ann_pose | \n","ann_truncated | \n","ann_difficult | \n","cat_id | \n","cat_name | \n","cat_supercategory | \n","split | \n","annotated | \n","
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | \n","\n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," | \n"," |
0 | \n","\n"," | IMG0000025.jpg | \n","\n"," | 1 | \n","2880 | \n","2304 | \n","\n"," | \n"," | 1466.504519 | \n","2010.557108 | \n","... | \n","[[1466.504519309778, 2010.557107641742, 1515.7... | \n","0 | \n","\n"," | \n"," | \n"," | 0 | \n","fractured | \n","\n"," | \n"," | 1 | \n","
1 | \n","\n"," | IMG0000044.jpg | \n","\n"," | 2 | \n","2304 | \n","2880 | \n","\n"," | \n"," | 1426.511093 | \n","1072.013147 | \n","... | \n","[[1554.300739523418, 1076.746096959737, 1457.2... | \n","0 | \n","\n"," | \n"," | \n"," | 0 | \n","fractured | \n","\n"," | \n"," | 1 | \n","
2 | \n","\n"," | IMG0000100.jpg | \n","\n"," | 3 | \n","2304 | \n","2880 | \n","\n"," | \n"," | 683.437962 | \n","1038.882498 | \n","... | \n","[[683.4379622021364, 1088.5784716516023, 685.8... | \n","0 | \n","\n"," | \n"," | \n"," | 0 | \n","fractured | \n","\n"," | \n"," | 1 | \n","
3 | \n","\n"," | IMG0000155.jpg | \n","\n"," | 4 | \n","2304 | \n","2880 | \n","\n"," | \n"," | 491.753492 | \n","1043.615448 | \n","... | \n","[[572.2136400986032, 1043.6154478225144, 515.4... | \n","0 | \n","\n"," | \n"," | \n"," | 0 | \n","fractured | \n","\n"," | \n"," | 1 | \n","
4 | \n","\n"," | IMG0000156.jpg | \n","\n"," | 5 | \n","2304 | \n","2880 | \n","\n"," | \n"," | 647.940838 | \n","1090.944947 | \n","... | \n","[[700.0032867707478, 1098.0443714050944, 657.4... | \n","0 | \n","\n"," | \n"," | \n"," | 0 | \n","fractured | \n","\n"," | \n"," | 1 | \n","
5 rows × 25 columns
\n","