{"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":"markdown","source":"# **Explore categories of whales and dophins**","metadata":{}},{"cell_type":"markdown","source":"Importing Libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom tensorflow.keras import layers,models\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom keras.callbacks import EarlyStopping\nimport warnings\nwarnings.simplefilter(\"ignore\")\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:39:25.408377Z","iopub.execute_input":"2022-02-09T11:39:25.408786Z","iopub.status.idle":"2022-02-09T11:39:25.413820Z","shell.execute_reply.started":"2022-02-09T11:39:25.408755Z","shell.execute_reply":"2022-02-09T11:39:25.412894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Importing Dataset","metadata":{}},{"cell_type":"code","source":"import os\nDir = '../input/happy-whale-and-dolphin'\nos.listdir(Dir)","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:25:01.530374Z","iopub.execute_input":"2022-02-09T11:25:01.530666Z","iopub.status.idle":"2022-02-09T11:25:01.539143Z","shell.execute_reply.started":"2022-02-09T11:25:01.530625Z","shell.execute_reply":"2022-02-09T11:25:01.538178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(os.listdir('../input/happy-whale-and-dolphin/train_images')))","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:25:28.161104Z","iopub.execute_input":"2022-02-09T11:25:28.161407Z","iopub.status.idle":"2022-02-09T11:25:29.345377Z","shell.execute_reply.started":"2022-02-09T11:25:28.161374Z","shell.execute_reply":"2022-02-09T11:25:29.344397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 51033 training images.","metadata":{}},{"cell_type":"code","source":"print(len(os.listdir('../input/happy-whale-and-dolphin/test_images')))","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:25:55.207168Z","iopub.execute_input":"2022-02-09T11:25:55.208103Z","iopub.status.idle":"2022-02-09T11:25:55.882613Z","shell.execute_reply.started":"2022-02-09T11:25:55.208051Z","shell.execute_reply":"2022-02-09T11:25:55.881758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 27956 test images.","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv('../input/happy-whale-and-dolphin/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:26:23.156866Z","iopub.execute_input":"2022-02-09T11:26:23.157809Z","iopub.status.idle":"2022-02-09T11:26:23.284661Z","shell.execute_reply.started":"2022-02-09T11:26:23.157761Z","shell.execute_reply":"2022-02-09T11:26:23.283834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see 3 different columns like image, species and individual_id.","metadata":{}},{"cell_type":"code","source":"train_df['species'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:29:38.024058Z","iopub.execute_input":"2022-02-09T11:29:38.024385Z","iopub.status.idle":"2022-02-09T11:29:38.037062Z","shell.execute_reply.started":"2022-02-09T11:29:38.024351Z","shell.execute_reply":"2022-02-09T11:29:38.035997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are 30 unique species present.","metadata":{}},{"cell_type":"code","source":"train_df['individual_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:30:14.039380Z","iopub.execute_input":"2022-02-09T11:30:14.039686Z","iopub.status.idle":"2022-02-09T11:30:14.051738Z","shell.execute_reply.started":"2022-02-09T11:30:14.039653Z","shell.execute_reply":"2022-02-09T11:30:14.050896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"There are in total 15587 individual_id's present in the data.","metadata":{}},{"cell_type":"markdown","source":"Let's start the visualisation party!!","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'humpback_whale'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:37:15.817076Z","iopub.execute_input":"2022-02-09T11:37:15.817672Z","iopub.status.idle":"2022-02-09T11:37:22.999465Z","shell.execute_reply.started":"2022-02-09T11:37:15.817620Z","shell.execute_reply":"2022-02-09T11:37:22.998580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some happy humback whales.","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'bottlenose_dolphin'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:37:52.732327Z","iopub.execute_input":"2022-02-09T11:37:52.733210Z","iopub.status.idle":"2022-02-09T11:38:00.553693Z","shell.execute_reply.started":"2022-02-09T11:37:52.733165Z","shell.execute_reply":"2022-02-09T11:38:00.552513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some happy bottlenose dolphins.","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'false_killer_whale'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:38:23.127358Z","iopub.execute_input":"2022-02-09T11:38:23.127671Z","iopub.status.idle":"2022-02-09T11:38:27.885369Z","shell.execute_reply.started":"2022-02-09T11:38:23.127640Z","shell.execute_reply":"2022-02-09T11:38:27.884479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some happy false killer whales.","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'melon_headed_whale'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:39:07.694893Z","iopub.execute_input":"2022-02-09T11:39:07.695429Z","iopub.status.idle":"2022-02-09T11:39:09.870144Z","shell.execute_reply.started":"2022-02-09T11:39:07.695380Z","shell.execute_reply":"2022-02-09T11:39:09.869379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some happy melon headed whales.","metadata":{}},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:44:30.137031Z","iopub.execute_input":"2022-02-09T11:44:30.137324Z","iopub.status.idle":"2022-02-09T11:44:30.152270Z","shell.execute_reply.started":"2022-02-09T11:44:30.137296Z","shell.execute_reply":"2022-02-09T11:44:30.151421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'beluga'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:44:46.770044Z","iopub.execute_input":"2022-02-09T11:44:46.770751Z","iopub.status.idle":"2022-02-09T11:44:48.285357Z","shell.execute_reply.started":"2022-02-09T11:44:46.770705Z","shell.execute_reply":"2022-02-09T11:44:48.284475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some happy beluga. It is not much clear from the name, but if google beluga then we found out that it is a type of whale only.","metadata":{}},{"cell_type":"code","source":"import cv2\nsample = train_df[train_df.species == 'blue_whale'].sample(9)\nplt.figure(figsize=(12,12))\nfor ind, (image_id, label) in enumerate(zip(sample.image, sample.species)):\n    plt.subplot(3, 3, ind + 1)\n    image = cv2.imread(os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image_id))\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.imshow(image)\n    plt.axis(\"off\")\n    \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-09T11:46:43.452601Z","iopub.execute_input":"2022-02-09T11:46:43.453559Z","iopub.status.idle":"2022-02-09T11:46:45.979019Z","shell.execute_reply.started":"2022-02-09T11:46:43.453497Z","shell.execute_reply":"2022-02-09T11:46:45.978074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"These are some of the beautiful blue whales.","metadata":{}}]}