{"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":"code","source":"import numpy as np\nimport pandas as pd \nimport json","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-19T04:48:31.717481Z","iopub.execute_input":"2022-02-19T04:48:31.717766Z","iopub.status.idle":"2022-02-19T04:48:31.722846Z","shell.execute_reply.started":"2022-02-19T04:48:31.717737Z","shell.execute_reply":"2022-02-19T04:48:31.721597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TRAIN_IMAGE_FOLDER = \"../input/herbarium-2022-fgvc9/train_images/\"\nTRAIN_JSON = \"../input/herbarium-2022-fgvc9/train_metadata.json\"\nNEW_TRAIN_CSV_PATH = \"train.csv\"\n\n\nTEST_IMAGE_FOLDER = \"../input/herbarium-2022-fgvc9/test_images/\"\nTEST_JSON = \"../input/herbarium-2022-fgvc9/test_metadata.json\"\nNEW_TEST_CSV_PATH = \"test.csv\"\n\nIMAGE_ID = \"image_id\"\nIMAGE_FILE_NAME = \"file_name\"\nIMAGE_TARGET = \"institution_id\"\nIMAGE_FILE_PATH = \"image_path\"","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:31.724402Z","iopub.execute_input":"2022-02-19T04:48:31.724648Z","iopub.status.idle":"2022-02-19T04:48:31.736262Z","shell.execute_reply.started":"2022-02-19T04:48:31.724618Z","shell.execute_reply":"2022-02-19T04:48:31.735378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# make train csv ","metadata":{}},{"cell_type":"code","source":"with open(TRAIN_JSON) as json_file:\n    train_data = json.load(json_file)","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:31.737596Z","iopub.execute_input":"2022-02-19T04:48:31.738399Z","iopub.status.idle":"2022-02-19T04:48:40.483815Z","shell.execute_reply.started":"2022-02-19T04:48:31.73835Z","shell.execute_reply":"2022-02-19T04:48:40.482709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_annotations = train_data[\"annotations\"]\nprint(\"train size=\",len(train_annotations))\ntrain_annotations[:3]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:40.485216Z","iopub.execute_input":"2022-02-19T04:48:40.485617Z","iopub.status.idle":"2022-02-19T04:48:40.496731Z","shell.execute_reply.started":"2022-02-19T04:48:40.485571Z","shell.execute_reply":"2022-02-19T04:48:40.495903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_genus_ids = [train_annotation[\"genus_id\"] for train_annotation in train_annotations]\ntrain_institution_ids = [train_annotation[IMAGE_TARGET] for train_annotation in train_annotations]\n# train_category_ids = [train_annotation[\"category_id\"] for train_annotation in train_annotations]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:40.498734Z","iopub.execute_input":"2022-02-19T04:48:40.499011Z","iopub.status.idle":"2022-02-19T04:48:40.566816Z","shell.execute_reply.started":"2022-02-19T04:48:40.498979Z","shell.execute_reply":"2022-02-19T04:48:40.565766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = train_data[\"images\"]\ntrain_images[:3]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:40.568235Z","iopub.execute_input":"2022-02-19T04:48:40.568479Z","iopub.status.idle":"2022-02-19T04:48:40.676899Z","shell.execute_reply.started":"2022-02-19T04:48:40.568452Z","shell.execute_reply":"2022-02-19T04:48:40.675896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_ids = [train_image[IMAGE_ID] for train_image in train_images]\n# train_file_names = [train_image[IMAGE_FILE_NAME] for train_image in train_images]\n# train_licenses = [train_image[\"license\"] for train_image in train_images]\n\ntrain_image_file_paths = [TRAIN_IMAGE_FOLDER + train_image[IMAGE_FILE_NAME] for train_image in train_images]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:40.678515Z","iopub.execute_input":"2022-02-19T04:48:40.678737Z","iopub.status.idle":"2022-02-19T04:48:40.994095Z","shell.execute_reply.started":"2022-02-19T04:48:40.678712Z","shell.execute_reply":"2022-02-19T04:48:40.99348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.DataFrame(data =np.array([train_image_ids ,train_image_file_paths,train_institution_ids]).T, \n                     columns = [IMAGE_ID, IMAGE_FILE_PATH,IMAGE_TARGET,])\ntrain.to_csv(NEW_TRAIN_CSV_PATH, index = False)\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:40.995955Z","iopub.execute_input":"2022-02-19T04:48:40.996286Z","iopub.status.idle":"2022-02-19T04:48:48.583418Z","shell.execute_reply.started":"2022-02-19T04:48:40.996244Z","shell.execute_reply":"2022-02-19T04:48:48.582203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.tail()","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:59.286623Z","iopub.execute_input":"2022-02-19T04:48:59.287297Z","iopub.status.idle":"2022-02-19T04:48:59.296896Z","shell.execute_reply.started":"2022-02-19T04:48:59.287261Z","shell.execute_reply":"2022-02-19T04:48:59.295964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# make test data","metadata":{}},{"cell_type":"code","source":"with open(TEST_JSON) as json_file:\n    test_data = json.load(json_file)\n    \ntest_data[:3]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:48.584606Z","iopub.execute_input":"2022-02-19T04:48:48.584816Z","iopub.status.idle":"2022-02-19T04:48:49.522452Z","shell.execute_reply.started":"2022-02-19T04:48:48.584792Z","shell.execute_reply":"2022-02-19T04:48:49.51782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_image_ids = [image[IMAGE_ID] for image in test_data]\ntest_image_path = [TEST_IMAGE_FOLDER + image[IMAGE_FILE_NAME] for image in test_data ]","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:49.529099Z","iopub.execute_input":"2022-02-19T04:48:49.530845Z","iopub.status.idle":"2022-02-19T04:48:49.78062Z","shell.execute_reply.started":"2022-02-19T04:48:49.530799Z","shell.execute_reply":"2022-02-19T04:48:49.777436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.DataFrame(data =np.array([test_image_ids , test_image_path ]).T, \n                    columns = [IMAGE_ID, IMAGE_FILE_PATH])\n\ntest.to_csv(NEW_TEST_CSV_PATH, index = False)\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-19T04:48:49.789076Z","iopub.execute_input":"2022-02-19T04:48:49.790475Z","iopub.status.idle":"2022-02-19T04:48:51.287797Z","shell.execute_reply.started":"2022-02-19T04:48:49.790291Z","shell.execute_reply":"2022-02-19T04:48:51.287011Z"},"trusted":true},"execution_count":null,"outputs":[]}]}