{"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\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor 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-19T09:30:38.075744Z","iopub.execute_input":"2021-12-19T09:30:38.076702Z","iopub.status.idle":"2021-12-19T09:30:43.755716Z","shell.execute_reply.started":"2021-12-19T09:30:38.076659Z","shell.execute_reply":"2021-12-19T09:30:43.753670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"execution":{"iopub.status.busy":"2021-12-19T09:30:43.760796Z","iopub.execute_input":"2021-12-19T09:30:43.761166Z","iopub.status.idle":"2021-12-19T09:30:43.766136Z","shell.execute_reply.started":"2021-12-19T09:30:43.761124Z","shell.execute_reply":"2021-12-19T09:30:43.765297Z"},"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-19T09:30:43.767182Z","iopub.execute_input":"2021-12-19T09:30:43.767376Z","iopub.status.idle":"2021-12-19T09:30:43.786003Z","shell.execute_reply.started":"2021-12-19T09:30:43.767353Z","shell.execute_reply":"2021-12-19T09:30:43.785196Z"},"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-19T09:30:43.787220Z","iopub.execute_input":"2021-12-19T09:30:43.787424Z","iopub.status.idle":"2021-12-19T09:30:43.825319Z","shell.execute_reply.started":"2021-12-19T09:30:43.787400Z","shell.execute_reply":"2021-12-19T09:30:43.824350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:30:43.827269Z","iopub.execute_input":"2021-12-19T09:30:43.827491Z","iopub.status.idle":"2021-12-19T09:30:43.840636Z","shell.execute_reply.started":"2021-12-19T09:30:43.827465Z","shell.execute_reply":"2021-12-19T09:30:43.839718Z"},"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-19T09:30:43.841932Z","iopub.execute_input":"2021-12-19T09:30:43.842159Z","iopub.status.idle":"2021-12-19T09:30:43.856742Z","shell.execute_reply.started":"2021-12-19T09:30:43.842125Z","shell.execute_reply":"2021-12-19T09:30:43.855918Z"},"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-19T09:30:43.857893Z","iopub.execute_input":"2021-12-19T09:30:43.858220Z","iopub.status.idle":"2021-12-19T09:30:43.922975Z","shell.execute_reply.started":"2021-12-19T09:30:43.858180Z","shell.execute_reply":"2021-12-19T09:30:43.922002Z"},"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-19T09:30:43.924362Z","iopub.execute_input":"2021-12-19T09:30:43.924843Z","iopub.status.idle":"2021-12-19T09:30:43.935660Z","shell.execute_reply.started":"2021-12-19T09:30:43.924768Z","shell.execute_reply":"2021-12-19T09:30:43.934631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"row = 7329","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:30:43.937050Z","iopub.execute_input":"2021-12-19T09:30:43.939404Z","iopub.status.idle":"2021-12-19T09:30:43.946745Z","shell.execute_reply.started":"2021-12-19T09:30:43.939349Z","shell.execute_reply":"2021-12-19T09:30:43.945952Z"},"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-19T09:30:43.948396Z","iopub.execute_input":"2021-12-19T09:30:43.948948Z","iopub.status.idle":"2021-12-19T09:30:43.959355Z","shell.execute_reply.started":"2021-12-19T09:30:43.948904Z","shell.execute_reply":"2021-12-19T09:30:43.957758Z"},"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-19T09:30:43.961024Z","iopub.execute_input":"2021-12-19T09:30:43.961325Z","iopub.status.idle":"2021-12-19T09:30:44.801528Z","shell.execute_reply.started":"2021-12-19T09:30:43.961285Z","shell.execute_reply":"2021-12-19T09:30:44.799945Z"},"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-19T09:30:44.803100Z","iopub.execute_input":"2021-12-19T09:30:44.803758Z","iopub.status.idle":"2021-12-19T09:30:44.810208Z","shell.execute_reply.started":"2021-12-19T09:30:44.803715Z","shell.execute_reply":"2021-12-19T09:30:44.809003Z"},"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-19T09:30:44.811751Z","iopub.execute_input":"2021-12-19T09:30:44.812438Z","iopub.status.idle":"2021-12-19T09:30:44.825086Z","shell.execute_reply.started":"2021-12-19T09:30:44.812393Z","shell.execute_reply":"2021-12-19T09:30:44.824344Z"},"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-19T09:30:44.828280Z","iopub.execute_input":"2021-12-19T09:30:44.829166Z","iopub.status.idle":"2021-12-19T09:30:44.863179Z","shell.execute_reply.started":"2021-12-19T09:30:44.829114Z","shell.execute_reply":"2021-12-19T09:30:44.862437Z"},"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-19T09:30:44.864313Z","iopub.execute_input":"2021-12-19T09:30:44.864966Z","iopub.status.idle":"2021-12-19T09:30:45.411242Z","shell.execute_reply.started":"2021-12-19T09:30:44.864923Z","shell.execute_reply":"2021-12-19T09:30:45.408849Z"},"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-19T09:30:45.412613Z","iopub.execute_input":"2021-12-19T09:30:45.413293Z","iopub.status.idle":"2021-12-19T09:30:45.435098Z","shell.execute_reply.started":"2021-12-19T09:30:45.413256Z","shell.execute_reply":"2021-12-19T09:30:45.433857Z"},"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-19T09:32:08.365833Z","iopub.execute_input":"2021-12-19T09:32:08.366249Z","iopub.status.idle":"2021-12-19T09:32:08.645060Z","shell.execute_reply.started":"2021-12-19T09:32:08.366219Z","shell.execute_reply":"2021-12-19T09:32:08.644421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PIL.Image.fromarray(pixel_array)","metadata":{"execution":{"iopub.status.busy":"2021-12-19T09:32:14.785187Z","iopub.execute_input":"2021-12-19T09:32:14.785981Z","iopub.status.idle":"2021-12-19T09:32:15.334315Z","shell.execute_reply.started":"2021-12-19T09:32:14.785943Z","shell.execute_reply":"2021-12-19T09:32:15.333128Z"},"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-19T09:32:22.273511Z","iopub.execute_input":"2021-12-19T09:32:22.273811Z","iopub.status.idle":"2021-12-19T09:32:22.280903Z","shell.execute_reply.started":"2021-12-19T09:32:22.273782Z","shell.execute_reply":"2021-12-19T09:32:22.280227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}