{"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 numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-02-03T03:17:30.142443Z","iopub.execute_input":"2022-02-03T03:17:30.142757Z","iopub.status.idle":"2022-02-03T03:17:59.254193Z","shell.execute_reply.started":"2022-02-03T03:17:30.142676Z","shell.execute_reply":"2022-02-03T03:17:59.253321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **OVERVIEW**\n\nThe data provided is a pool of images of sea creatures, claimed to be of Whales and Dolhins. The data in this competition contains images of over 15,000 unique individual marine mammals from 30 different species collected from 28 different research organizations. Individuals have been manually identified and given an individual_id by marine researches.\n\nThe task is to correctly identify these individuals in the images. It's a challenging task that has the potential to drive significant advancements in understanding and protecting marine mammals across the globe.\n\nThis is an image classification problem .I will be using Convolutional Neural Networks (CNNs) technique for the solution. ","metadata":{}},{"cell_type":"markdown","source":"# **PROCESS STEPS**","metadata":{}},{"cell_type":"markdown","source":"The rough archtecture of the process flow steps is covered through following 6 steps. I will keem modifying the steps based on the need as I move ahead.\n\n**Step 0:** Import Datasets\n\n**Step 1:** Detect Dolphin and Whales\n\n**Step 2:** Create a CNN to Classify Dolphin & Whales Species\n\n**Step 3:** Use a CNN to Classify Dolphin & Whales Species\n\n**Step 4:** Algorithm writing\n\n**Step 5:** Algorithm testing\n","metadata":{}},{"cell_type":"markdown","source":"# **Step 0:** Import Datasets","metadata":{}},{"cell_type":"code","source":"path = '/kaggle/input/happy-whale-and-dolphin/'\nos.listdir(path)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:17:59.256016Z","iopub.execute_input":"2022-02-03T03:17:59.256685Z","iopub.status.idle":"2022-02-03T03:17:59.266363Z","shell.execute_reply.started":"2022-02-03T03:17:59.25664Z","shell.execute_reply":"2022-02-03T03:17:59.265709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the datasets\ntrain_img_folder = '/kaggle/input/happy-whale-and-dolphin/train_images'\ntest_img_folder = '/kaggle/input/happy-whale-and-dolphin/test_images'\n\nsample_submission = pd.read_csv(\"../input/happy-whale-and-dolphin/sample_submission.csv\")\ntrain = pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:17:59.267299Z","iopub.execute_input":"2022-02-03T03:17:59.267878Z","iopub.status.idle":"2022-02-03T03:17:59.444836Z","shell.execute_reply.started":"2022-02-03T03:17:59.267846Z","shell.execute_reply":"2022-02-03T03:17:59.444153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:17:59.446303Z","iopub.execute_input":"2022-02-03T03:17:59.44689Z","iopub.status.idle":"2022-02-03T03:17:59.48781Z","shell.execute_reply.started":"2022-02-03T03:17:59.446858Z","shell.execute_reply":"2022-02-03T03:17:59.486998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:17:59.48924Z","iopub.execute_input":"2022-02-03T03:17:59.48964Z","iopub.status.idle":"2022-02-03T03:17:59.504182Z","shell.execute_reply.started":"2022-02-03T03:17:59.489595Z","shell.execute_reply":"2022-02-03T03:17:59.503417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking for species categories distribution\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nspecies_count  = train['species'].value_counts()\n\nplt.figure(figsize=(20,7))\ng=sns.barplot(species_count.index, species_count.values, alpha=0.8)\nplt.title('Variety of Whales and Dolphin Species')\nplt.ylabel('Count', fontsize=12)\nplt.xlabel('Species Type', fontsize=12)\nplt.xticks(rotation=75)\nfor p in g.patches:\n    g.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:17:59.507579Z","iopub.execute_input":"2022-02-03T03:17:59.50799Z","iopub.status.idle":"2022-02-03T03:18:01.112866Z","shell.execute_reply.started":"2022-02-03T03:17:59.507959Z","shell.execute_reply":"2022-02-03T03:18:01.111741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the number of unique species in train data set\nspecies = train.species.unique()\nspecies","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:01.114658Z","iopub.execute_input":"2022-02-03T03:18:01.114992Z","iopub.status.idle":"2022-02-03T03:18:01.127163Z","shell.execute_reply.started":"2022-02-03T03:18:01.114932Z","shell.execute_reply":"2022-02-03T03:18:01.126176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.DataFrame(species,columns=['text'])\n\nx = df.text.apply(lambda x: pd.value_counts(x.split(\"_\"))).sum(axis = 0)\nx.plot(kind= 'barh', figsize = (10, 8))","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:01.128325Z","iopub.execute_input":"2022-02-03T03:18:01.128567Z","iopub.status.idle":"2022-02-03T03:18:01.607545Z","shell.execute_reply.started":"2022-02-03T03:18:01.128532Z","shell.execute_reply":"2022-02-03T03:18:01.606837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Step 1: Detect Dolphin and Whales","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nimport cv2\nfrom tensorflow import keras\nfrom  matplotlib import pyplot as plt\nimport matplotlib.image as mpimg\nimport random\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:01.608652Z","iopub.execute_input":"2022-02-03T03:18:01.608891Z","iopub.status.idle":"2022-02-03T03:18:06.816759Z","shell.execute_reply.started":"2022-02-03T03:18:01.608864Z","shell.execute_reply":"2022-02-03T03:18:06.815749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking first few images from training data\n\n\ndef load_image(folder, count):\n    plt.figure(figsize=(20,20))\n    for i in range(count):\n        file = random.choice(os.listdir(folder))\n        image_path= os.path.join(folder, file)\n        img=mpimg.imread(image_path)\n        ax=plt.subplot(1,count,i+1)\n        ax.title.set_text(file)\n        plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:06.819004Z","iopub.execute_input":"2022-02-03T03:18:06.81923Z","iopub.status.idle":"2022-02-03T03:18:06.82513Z","shell.execute_reply.started":"2022-02-03T03:18:06.819205Z","shell.execute_reply":"2022-02-03T03:18:06.82422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Loading few random images from train data\nload_image(train_img_folder,5)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:06.826633Z","iopub.execute_input":"2022-02-03T03:18:06.827182Z","iopub.status.idle":"2022-02-03T03:18:11.353244Z","shell.execute_reply.started":"2022-02-03T03:18:06.827124Z","shell.execute_reply":"2022-02-03T03:18:11.352525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Loading few irandom mages from test data\nload_image(test_img_folder,5)","metadata":{"execution":{"iopub.status.busy":"2022-02-03T03:18:11.354266Z","iopub.execute_input":"2022-02-03T03:18:11.354997Z","iopub.status.idle":"2022-02-03T03:18:16.163583Z","shell.execute_reply.started":"2022-02-03T03:18:11.354963Z","shell.execute_reply":"2022-02-03T03:18:16.162631Z"},"trusted":true},"execution_count":null,"outputs":[]}]}