{"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 cv2\nimport ast\nimport numpy as np\nimport pandas as pd\nimport matplotlib\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-08T06:08:25.633685Z","iopub.execute_input":"2021-12-08T06:08:25.634021Z","iopub.status.idle":"2021-12-08T06:08:25.906801Z","shell.execute_reply.started":"2021-12-08T06:08:25.633936Z","shell.execute_reply":"2021-12-08T06:08:25.906133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/tensorflow-great-barrier-reef/'\nos.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:25.908913Z","iopub.execute_input":"2021-12-08T06:08:25.909201Z","iopub.status.idle":"2021-12-08T06:08:25.919948Z","shell.execute_reply.started":"2021-12-08T06:08:25.909161Z","shell.execute_reply":"2021-12-08T06:08:25.918996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(path+'train.csv')\ntest_data = pd.read_csv(path+'test.csv')\nsamp_subm = pd.read_csv(path+'example_sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:25.921329Z","iopub.execute_input":"2021-12-08T06:08:25.921852Z","iopub.status.idle":"2021-12-08T06:08:25.990336Z","shell.execute_reply.started":"2021-12-08T06:08:25.921819Z","shell.execute_reply":"2021-12-08T06:08:25.989562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:25.992746Z","iopub.execute_input":"2021-12-08T06:08:25.993055Z","iopub.status.idle":"2021-12-08T06:08:26.011702Z","shell.execute_reply.started":"2021-12-08T06:08:25.993015Z","shell.execute_reply":"2021-12-08T06:08:26.010885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"video_frame = 621\nfile_name = str(video_frame)+'.jpg'\ntrain_data[train_data['video_frame']==video_frame]","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.013112Z","iopub.execute_input":"2021-12-08T06:08:26.013654Z","iopub.status.idle":"2021-12-08T06:08:26.032649Z","shell.execute_reply.started":"2021-12-08T06:08:26.01361Z","shell.execute_reply":"2021-12-08T06:08:26.031903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_folder_0 = cv2.imread(path+'train_images/video_0/'+file_name)\nimage_folder_1 = cv2.imread(path+'train_images/video_1/'+file_name)\nimage_folder_2 = cv2.imread(path+'train_images/video_2/'+file_name)","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.033611Z","iopub.execute_input":"2021-12-08T06:08:26.03397Z","iopub.status.idle":"2021-12-08T06:08:26.131047Z","shell.execute_reply.started":"2021-12-08T06:08:26.033939Z","shell.execute_reply":"2021-12-08T06:08:26.130297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data[(train_data['video_frame']==video_frame)&(train_data['video_id']==1)]['annotations']","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.132245Z","iopub.execute_input":"2021-12-08T06:08:26.132688Z","iopub.status.idle":"2021-12-08T06:08:26.142646Z","shell.execute_reply.started":"2021-12-08T06:08:26.132646Z","shell.execute_reply":"2021-12-08T06:08:26.14184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row = 7329","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.144216Z","iopub.execute_input":"2021-12-08T06:08:26.144792Z","iopub.status.idle":"2021-12-08T06:08:26.153776Z","shell.execute_reply.started":"2021-12-08T06:08:26.144751Z","shell.execute_reply":"2021-12-08T06:08:26.153144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"boxes = ast.literal_eval(train_data.loc[row, 'annotations'])","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.154656Z","iopub.execute_input":"2021-12-08T06:08:26.155219Z","iopub.status.idle":"2021-12-08T06:08:26.1699Z","shell.execute_reply.started":"2021-12-08T06:08:26.155185Z","shell.execute_reply":"2021-12-08T06:08:26.169023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 1, figsize=(20, 8))\nax.imshow(image_folder_1)\nfor box in boxes:\n    p = matplotlib.patches.Rectangle((box['x'], box['y']), box['width'], box['height'],\n                                     ec='r', fc='none', lw=2.)\n    ax.add_patch(p)\nax.set_xticklabels([])\nax.set_yticklabels([])\nplt.savefig(\"oh_no_one_reef_eater.png\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:26.171914Z","iopub.execute_input":"2021-12-08T06:08:26.172376Z","iopub.status.idle":"2021-12-08T06:08:27.016932Z","shell.execute_reply.started":"2021-12-08T06:08:26.172341Z","shell.execute_reply":"2021-12-08T06:08:27.015731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row = 2845\nfile_name = str(train_data.loc[row, 'video_frame'])+'.jpg'\nvideo_folder = 'video_'+str(train_data.loc[row, 'video_id'])\nboxes = ast.literal_eval(train_data.loc[row, 'annotations'])","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.018251Z","iopub.execute_input":"2021-12-08T06:08:27.018559Z","iopub.status.idle":"2021-12-08T06:08:27.025103Z","shell.execute_reply.started":"2021-12-08T06:08:27.018523Z","shell.execute_reply":"2021-12-08T06:08:27.024166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('video folder:', video_folder)\nprint('file name:', file_name)","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.026307Z","iopub.execute_input":"2021-12-08T06:08:27.026601Z","iopub.status.idle":"2021-12-08T06:08:27.038313Z","shell.execute_reply.started":"2021-12-08T06:08:27.026565Z","shell.execute_reply":"2021-12-08T06:08:27.037475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = cv2.imread(path+'train_images/'+video_folder+'/'+file_name)\nimage.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.039811Z","iopub.execute_input":"2021-12-08T06:08:27.040136Z","iopub.status.idle":"2021-12-08T06:08:27.085026Z","shell.execute_reply.started":"2021-12-08T06:08:27.040093Z","shell.execute_reply":"2021-12-08T06:08:27.084281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 1, figsize=(20, 8))\nax.imshow(image)\nfor box in boxes:\n    p = matplotlib.patches.Rectangle((box['x'], box['y']), box['width'], box['height'],\n                                     ec='r', fc='none', lw=2.)\n    ax.add_patch(p)\nax.set_xticklabels([])\nax.set_yticklabels([])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.086473Z","iopub.execute_input":"2021-12-08T06:08:27.086791Z","iopub.status.idle":"2021-12-08T06:08:27.700795Z","shell.execute_reply.started":"2021-12-08T06:08:27.08675Z","shell.execute_reply":"2021-12-08T06:08:27.700062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import PIL.Image\n\n# these sys calls aren't actually necesarry in Kaggle notebooks, but you may need to add the data directory to your pythonpath to run the sample API off of Kaggle\nimport sys\nsys.path.append('../input/tensorflow-great-barrier-reef')   \n\nimport greatbarrierreef\nenv = greatbarrierreef.make_env()   # initialize the environment\niter_test = env.iter_test()","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.701925Z","iopub.execute_input":"2021-12-08T06:08:27.702688Z","iopub.status.idle":"2021-12-08T06:08:27.730821Z","shell.execute_reply.started":"2021-12-08T06:08:27.70265Z","shell.execute_reply":"2021-12-08T06:08:27.730028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pixel_array, sample_prediction_df = next(iter_test)\npixel_array","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:27.731976Z","iopub.execute_input":"2021-12-08T06:08:27.732484Z","iopub.status.idle":"2021-12-08T06:08:28.079068Z","shell.execute_reply.started":"2021-12-08T06:08:27.732443Z","shell.execute_reply":"2021-12-08T06:08:28.07824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PIL.Image.fromarray(pixel_array)","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:28.080209Z","iopub.execute_input":"2021-12-08T06:08:28.080412Z","iopub.status.idle":"2021-12-08T06:08:28.635211Z","shell.execute_reply.started":"2021-12-08T06:08:28.080389Z","shell.execute_reply":"2021-12-08T06:08:28.634313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp_subm.to_csv('submission.csv', index=False) # Remember: name your submission, submission.csv!","metadata":{"execution":{"iopub.status.busy":"2021-12-08T06:08:28.636282Z","iopub.execute_input":"2021-12-08T06:08:28.636521Z","iopub.status.idle":"2021-12-08T06:08:28.643437Z","shell.execute_reply.started":"2021-12-08T06:08:28.636478Z","shell.execute_reply":"2021-12-08T06:08:28.642581Z"},"trusted":true},"execution_count":null,"outputs":[]}]}