{"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, glob\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nDATASET_FOLDER = \"/kaggle/input/blood-vessel-segmentation\"","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-13T00:10:49.522519Z","iopub.execute_input":"2023-11-13T00:10:49.523252Z","iopub.status.idle":"2023-11-13T00:10:49.974301Z","shell.execute_reply.started":"2023-11-13T00:10:49.523214Z","shell.execute_reply":"2023-11-13T00:10:49.972688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(os.path.join(DATASET_FOLDER, \"train_rles.csv\"))\ndf_train[[\"dataset\", \"slice\"]] = df_train['id'].str.rsplit(pat='_', n=1, expand=True)\ndisplay(df_train.head())","metadata":{"execution":{"iopub.status.busy":"2023-11-13T00:10:49.976720Z","iopub.execute_input":"2023-11-13T00:10:49.977402Z","iopub.status.idle":"2023-11-13T00:10:51.228838Z","shell.execute_reply.started":"2023-11-13T00:10:49.977354Z","shell.execute_reply":"2023-11-13T00:10:51.227953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"uq_datasets = df_train[\"dataset\"].unique()\nprint(f\"parsed {len(uq_datasets)} unique datasets: {uq_datasets}\")","metadata":{"execution":{"iopub.status.busy":"2023-11-13T00:10:51.230061Z","iopub.execute_input":"2023-11-13T00:10:51.231108Z","iopub.status.idle":"2023-11-13T00:10:51.243037Z","shell.execute_reply.started":"2023-11-13T00:10:51.231058Z","shell.execute_reply":"2023-11-13T00:10:51.242071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls_images = glob.glob(os.path.join(DATASET_FOLDER, \"test\", \"*\", \"*\", \"*.tif\"))\nprint(f\"found images: {len(ls_images)}\")","metadata":{"execution":{"iopub.status.busy":"2023-11-13T00:11:30.451148Z","iopub.execute_input":"2023-11-13T00:11:30.451590Z","iopub.status.idle":"2023-11-13T00:11:30.474094Z","shell.execute_reply.started":"2023-11-13T00:11:30.451557Z","shell.execute_reply":"2023-11-13T00:11:30.472901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.auto import tqdm\n\nsubmission = []\nfor p_img in tqdm(ls_images):\n    path_ = p_img.split(os.path.sep)\n    # parse the submission ID\n    dataset = path_[-3]\n    slice_id, _ = os.path.splitext(path_[-1])\n    # load image to get dimension\n    img = plt.imread(p_img)\n    # sample mask with rectangle\n    mask = np.zeros(img.shape[:2])\n    i, j = int(img.shape[0] / 3), int(img.shape[1] / 4)\n    mask[i:i+50, j:j+100] = 1\n    # submission entry\n    submission.append({\n        \"id\": f\"{dataset}_{slice_id}\",\n        #\"rle\": rle_encode(mask),\n        \"rle\": \"1 1\",\n    })","metadata":{"execution":{"iopub.status.busy":"2023-11-13T00:11:31.184673Z","iopub.execute_input":"2023-11-13T00:11:31.186010Z","iopub.status.idle":"2023-11-13T00:11:31.568607Z","shell.execute_reply.started":"2023-11-13T00:11:31.185946Z","shell.execute_reply":"2023-11-13T00:11:31.567167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub = pd.DataFrame(submission)\ndisplay(df_sub.head())\ndf_sub.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2023-11-13T00:11:31.571114Z","iopub.execute_input":"2023-11-13T00:11:31.571507Z","iopub.status.idle":"2023-11-13T00:11:31.587715Z","shell.execute_reply.started":"2023-11-13T00:11:31.571473Z","shell.execute_reply":"2023-11-13T00:11:31.586185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}