{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\n#import numpy as np # linear algebra\n#import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport cv2\nimport ast\nimport numpy as np\nimport pandas as pd\nimport matplotlib\nimport matplotlib.pyplot as plt\n\n#import os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n#    for filename in filenames:\n#        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-09T14:13:57.798045Z","iopub.execute_input":"2021-12-09T14:13:57.798267Z","iopub.status.idle":"2021-12-09T14:13:58.054620Z","shell.execute_reply.started":"2021-12-09T14:13:57.798244Z","shell.execute_reply":"2021-12-09T14:13:58.053217Z"},"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-09T14:14:12.124653Z","iopub.execute_input":"2021-12-09T14:14:12.125687Z","iopub.status.idle":"2021-12-09T14:14:12.139032Z","shell.execute_reply.started":"2021-12-09T14:14:12.125646Z","shell.execute_reply":"2021-12-09T14:14:12.138220Z"},"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-09T14:14:28.632973Z","iopub.execute_input":"2021-12-09T14:14:28.633455Z","iopub.status.idle":"2021-12-09T14:14:28.695494Z","shell.execute_reply.started":"2021-12-09T14:14:28.633424Z","shell.execute_reply":"2021-12-09T14:14:28.694829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T14:14:42.199740Z","iopub.execute_input":"2021-12-09T14:14:42.199971Z","iopub.status.idle":"2021-12-09T14:14:42.219203Z","shell.execute_reply.started":"2021-12-09T14:14:42.199946Z","shell.execute_reply":"2021-12-09T14:14:42.217570Z"},"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-09T14:14:59.088226Z","iopub.execute_input":"2021-12-09T14:14:59.088625Z","iopub.status.idle":"2021-12-09T14:14:59.106851Z","shell.execute_reply.started":"2021-12-09T14:14:59.088598Z","shell.execute_reply":"2021-12-09T14:14:59.105955Z"},"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-09T14:15:12.757649Z","iopub.execute_input":"2021-12-09T14:15:12.757963Z","iopub.status.idle":"2021-12-09T14:15:12.888317Z","shell.execute_reply.started":"2021-12-09T14:15:12.757924Z","shell.execute_reply":"2021-12-09T14:15:12.886811Z"},"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-09T14:15:24.620795Z","iopub.execute_input":"2021-12-09T14:15:24.621884Z","iopub.status.idle":"2021-12-09T14:15:24.632887Z","shell.execute_reply.started":"2021-12-09T14:15:24.621853Z","shell.execute_reply":"2021-12-09T14:15:24.632215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row = 7329","metadata":{"execution":{"iopub.status.busy":"2021-12-09T14:15:42.277165Z","iopub.execute_input":"2021-12-09T14:15:42.277415Z","iopub.status.idle":"2021-12-09T14:15:42.282495Z","shell.execute_reply.started":"2021-12-09T14:15:42.277390Z","shell.execute_reply":"2021-12-09T14:15:42.281619Z"},"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-09T14:15:53.992992Z","iopub.execute_input":"2021-12-09T14:15:53.993279Z","iopub.status.idle":"2021-12-09T14:15:54.001864Z","shell.execute_reply.started":"2021-12-09T14:15:53.993249Z","shell.execute_reply":"2021-12-09T14:15:54.000274Z"},"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-09T14:16:08.442368Z","iopub.execute_input":"2021-12-09T14:16:08.442690Z","iopub.status.idle":"2021-12-09T14:16:09.194362Z","shell.execute_reply.started":"2021-12-09T14:16:08.442668Z","shell.execute_reply":"2021-12-09T14:16:09.193645Z"},"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-09T14:16:26.147259Z","iopub.execute_input":"2021-12-09T14:16:26.147885Z","iopub.status.idle":"2021-12-09T14:16:26.153286Z","shell.execute_reply.started":"2021-12-09T14:16:26.147848Z","shell.execute_reply":"2021-12-09T14:16:26.152331Z"},"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-09T14:16:38.657129Z","iopub.execute_input":"2021-12-09T14:16:38.657574Z","iopub.status.idle":"2021-12-09T14:16:38.662177Z","shell.execute_reply.started":"2021-12-09T14:16:38.657539Z","shell.execute_reply":"2021-12-09T14:16:38.661539Z"},"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-09T14:16:53.294267Z","iopub.execute_input":"2021-12-09T14:16:53.294513Z","iopub.status.idle":"2021-12-09T14:16:53.334293Z","shell.execute_reply.started":"2021-12-09T14:16:53.294488Z","shell.execute_reply":"2021-12-09T14:16:53.333857Z"},"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-09T14:17:05.412631Z","iopub.execute_input":"2021-12-09T14:17:05.413182Z","iopub.status.idle":"2021-12-09T14:17:05.851188Z","shell.execute_reply.started":"2021-12-09T14:17:05.413156Z","shell.execute_reply":"2021-12-09T14:17:05.850463Z"},"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-09T14:17:20.589051Z","iopub.execute_input":"2021-12-09T14:17:20.589294Z","iopub.status.idle":"2021-12-09T14:17:20.594120Z","shell.execute_reply.started":"2021-12-09T14:17:20.589270Z","shell.execute_reply":"2021-12-09T14:17:20.593033Z"},"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-09T14:17:33.573596Z","iopub.execute_input":"2021-12-09T14:17:33.573968Z","iopub.status.idle":"2021-12-09T14:17:33.863722Z","shell.execute_reply.started":"2021-12-09T14:17:33.573941Z","shell.execute_reply":"2021-12-09T14:17:33.863265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PIL.Image.fromarray(pixel_array)","metadata":{"execution":{"iopub.status.busy":"2021-12-09T14:17:48.372861Z","iopub.execute_input":"2021-12-09T14:17:48.373186Z","iopub.status.idle":"2021-12-09T14:17:48.833346Z","shell.execute_reply.started":"2021-12-09T14:17:48.373163Z","shell.execute_reply":"2021-12-09T14:17:48.832490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp_subm.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2021-12-09T14:18:06.692730Z","iopub.execute_input":"2021-12-09T14:18:06.692981Z","iopub.status.idle":"2021-12-09T14:18:06.702166Z","shell.execute_reply.started":"2021-12-09T14:18:06.692957Z","shell.execute_reply":"2021-12-09T14:18:06.701310Z"},"trusted":true},"execution_count":null,"outputs":[]}]}