{"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-09T03:16:25.228757Z","iopub.execute_input":"2021-12-09T03:16:25.229104Z","iopub.status.idle":"2021-12-09T03:16:32.175351Z","shell.execute_reply.started":"2021-12-09T03:16:25.229065Z","shell.execute_reply":"2021-12-09T03:16:32.174455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport os\n\nimport matplotlib.pyplot as plt\n\nimport pathlib\nimport PIL\n\nfrom pathlib import Path","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.177215Z","iopub.execute_input":"2021-12-09T03:16:32.177459Z","iopub.status.idle":"2021-12-09T03:16:32.184270Z","shell.execute_reply.started":"2021-12-09T03:16:32.177431Z","shell.execute_reply":"2021-12-09T03:16:32.183109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"../input/tensorflow-great-barrier-reef/train.csv\")\ntest = pd.read_csv(\"../input/tensorflow-great-barrier-reef/test.csv\")\nsub = pd.read_csv(\"../input/tensorflow-great-barrier-reef/example_sample_submission.csv\")\n\npath = Path('../input/tensorflow-great-barrier-reef/train_images')\nfilepaths = list(path.glob(r'**/*.jpg'))","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.186786Z","iopub.execute_input":"2021-12-09T03:16:32.187196Z","iopub.status.idle":"2021-12-09T03:16:32.491244Z","shell.execute_reply.started":"2021-12-09T03:16:32.187139Z","shell.execute_reply":"2021-12-09T03:16:32.490046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.493335Z","iopub.execute_input":"2021-12-09T03:16:32.493777Z","iopub.status.idle":"2021-12-09T03:16:32.508383Z","shell.execute_reply.started":"2021-12-09T03:16:32.493736Z","shell.execute_reply":"2021-12-09T03:16:32.507190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.loc[train[\"annotations\"] != \"[]\"]\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.509724Z","iopub.execute_input":"2021-12-09T03:16:32.510144Z","iopub.status.idle":"2021-12-09T03:16:32.534297Z","shell.execute_reply.started":"2021-12-09T03:16:32.510108Z","shell.execute_reply":"2021-12-09T03:16:32.533228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.535926Z","iopub.execute_input":"2021-12-09T03:16:32.536701Z","iopub.status.idle":"2021-12-09T03:16:32.552431Z","shell.execute_reply.started":"2021-12-09T03:16:32.536652Z","shell.execute_reply":"2021-12-09T03:16:32.551632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.554351Z","iopub.execute_input":"2021-12-09T03:16:32.554733Z","iopub.status.idle":"2021-12-09T03:16:32.571281Z","shell.execute_reply.started":"2021-12-09T03:16:32.554685Z","shell.execute_reply":"2021-12-09T03:16:32.570420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape , test.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.572472Z","iopub.execute_input":"2021-12-09T03:16:32.573274Z","iopub.status.idle":"2021-12-09T03:16:32.581057Z","shell.execute_reply.started":"2021-12-09T03:16:32.573227Z","shell.execute_reply":"2021-12-09T03:16:32.580368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.582216Z","iopub.execute_input":"2021-12-09T03:16:32.583041Z","iopub.status.idle":"2021-12-09T03:16:32.602993Z","shell.execute_reply.started":"2021-12-09T03:16:32.582979Z","shell.execute_reply":"2021-12-09T03:16:32.601780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.605785Z","iopub.execute_input":"2021-12-09T03:16:32.606543Z","iopub.status.idle":"2021-12-09T03:16:32.618215Z","shell.execute_reply.started":"2021-12-09T03:16:32.606497Z","shell.execute_reply":"2021-12-09T03:16:32.616701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(train.isnull().sum()/ len(train))*100 ","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.619510Z","iopub.execute_input":"2021-12-09T03:16:32.619787Z","iopub.status.idle":"2021-12-09T03:16:32.632396Z","shell.execute_reply.started":"2021-12-09T03:16:32.619756Z","shell.execute_reply":"2021-12-09T03:16:32.631708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getLastFolderName(x): \n    pathwithoutFilename = os.path.split(x)[0] \n    lastFolderName = pathwithoutFilename.split(\"/\")[-1] \n    return lastFolderName\n\ntargets = list(map(lambda x: getLastFolderName(x),filepaths)) \ntargets[:5]","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.633448Z","iopub.execute_input":"2021-12-09T03:16:32.634203Z","iopub.status.idle":"2021-12-09T03:16:32.748056Z","shell.execute_reply.started":"2021-12-09T03:16:32.634161Z","shell.execute_reply":"2021-12-09T03:16:32.746742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_Imagepath = pd.Series(filepaths, name='ImagePath').astype(str)\ncolumn_ImageType = pd.Series(targets, name='ImageType').astype(str)\n\ntrain = pd.merge(column_Imagepath, column_ImageType, right_index = True, left_index = True)\ntrain= train.sample(frac = 1).reset_index(drop=True) # all shuffle \ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.749288Z","iopub.execute_input":"2021-12-09T03:16:32.749518Z","iopub.status.idle":"2021-12-09T03:16:32.789988Z","shell.execute_reply.started":"2021-12-09T03:16:32.749491Z","shell.execute_reply":"2021-12-09T03:16:32.788915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f,a = plt.subplots(nrows=4, ncols=4,figsize=(15, 10),\n                        subplot_kw={'xticks': [], 'yticks': []})\n\nfor i, ax in enumerate(a.flat):\n    ax.imshow(plt.imread(train.ImagePath[i]))\n    ax.set_title(train.ImageType[i])\n    \nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-09T03:16:32.791448Z","iopub.execute_input":"2021-12-09T03:16:32.792468Z","iopub.status.idle":"2021-12-09T03:16:36.713667Z","shell.execute_reply.started":"2021-12-09T03:16:32.792428Z","shell.execute_reply":"2021-12-09T03:16:36.712886Z"},"trusted":true},"execution_count":null,"outputs":[]}]}