{"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 os\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport torchvision.transforms as transforms","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-15T20:55:26.289397Z","iopub.execute_input":"2022-03-15T20:55:26.289707Z","iopub.status.idle":"2022-03-15T20:55:27.512872Z","shell.execute_reply.started":"2022-03-15T20:55:26.289675Z","shell.execute_reply":"2022-03-15T20:55:27.511925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:45:37.660153Z","iopub.execute_input":"2022-03-15T20:45:37.660383Z","iopub.status.idle":"2022-03-15T20:45:37.665041Z","shell.execute_reply.started":"2022-03-15T20:45:37.660355Z","shell.execute_reply":"2022-03-15T20:45:37.664213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_path = '../input/airbus-ship-detection/'\ntrain_dpath = dataset_path + 'train_v2'\ntest_dpath = dataset_path + 'test_v2'\nanno_fpath = dataset_path + 'train_ship_segmentations_v2.csv'\nsample_submission_fpath = dataset_path + 'sample_submission_v2.csv'","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:45:37.666104Z","iopub.execute_input":"2022-03-15T20:45:37.666352Z","iopub.status.idle":"2022-03-15T20:45:37.675257Z","shell.execute_reply.started":"2022-03-15T20:45:37.666315Z","shell.execute_reply":"2022-03-15T20:45:37.6745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv(anno_fpath)","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:45:37.6762Z","iopub.execute_input":"2022-03-15T20:45:37.676802Z","iopub.status.idle":"2022-03-15T20:45:38.734882Z","shell.execute_reply.started":"2022-03-15T20:45:37.676764Z","shell.execute_reply":"2022-03-15T20:45:38.73416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels['exist_ship'] = labels['EncodedPixels'].fillna(0)\nlabels.loc[labels['exist_ship'] != 0, 'exist_ship'] = 1\ndel labels['EncodedPixels']","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:46:12.299802Z","iopub.execute_input":"2022-03-15T20:46:12.300101Z","iopub.status.idle":"2022-03-15T20:46:12.380563Z","shell.execute_reply.started":"2022-03-15T20:46:12.300068Z","shell.execute_reply":"2022-03-15T20:46:12.379619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# remove dublicate images\nprint(len(labels['ImageId']))\nprint(labels['ImageId'].value_counts().shape[0])\ntrain_gp = labels.groupby('ImageId').sum().reset_index()\ntrain_gp.loc[train_gp['exist_ship'] > 0, 'exist_ship'] = 1","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:46:26.945015Z","iopub.execute_input":"2022-03-15T20:46:26.945292Z","iopub.status.idle":"2022-03-15T20:46:27.382778Z","shell.execute_reply.started":"2022-03-15T20:46:26.945264Z","shell.execute_reply":"2022-03-15T20:46:27.382193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# balance ship and no ship data\nprint(train_gp['exist_ship'].value_counts())\nlabel = 'Has Ship', 'Hasn\\'t Ship'\nplt.figure(figsize = (8,8))\nplt.pie(train_gp.groupby('exist_ship').size(), labels = label, autopct='%1.1f%%', shadow=True, startangle=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:46:29.895218Z","iopub.execute_input":"2022-03-15T20:46:29.895722Z","iopub.status.idle":"2022-03-15T20:46:30.102247Z","shell.execute_reply.started":"2022-03-15T20:46:29.895689Z","shell.execute_reply":"2022-03-15T20:46:30.101406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_gp = train_gp.sort_values(by='exist_ship')\ntrain_gp = train_gp.drop(train_gp.index[0:107444])","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:46:42.10344Z","iopub.execute_input":"2022-03-15T20:46:42.103752Z","iopub.status.idle":"2022-03-15T20:46:42.171268Z","shell.execute_reply.started":"2022-03-15T20:46:42.103718Z","shell.execute_reply":"2022-03-15T20:46:42.170522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# balance ship and no ship data\nprint(train_gp['exist_ship'].value_counts())\nlabel = 'Has Ship', 'Hasn\\'t Ship'\nplt.figure(figsize = (8,8))\nplt.pie(train_gp.groupby('exist_ship').size(), labels = label, autopct='%1.1f%%', shadow=True, startangle=90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-15T20:46:43.895114Z","iopub.execute_input":"2022-03-15T20:46:43.895391Z","iopub.status.idle":"2022-03-15T20:46:44.118535Z","shell.execute_reply.started":"2022-03-15T20:46:43.895359Z","shell.execute_reply":"2022-03-15T20:46:44.117442Z"},"trusted":true},"execution_count":null,"outputs":[]}]}