{"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":"# <div style=\"margin:0;font-size:35px;font-family:verdana;text-align:center;display:fill;border-radius:5px;overflow:hidden;\">🐦Bird CLEF 23 - Starter EDA🎼</div>\n\n<br>    \n<p style=\"text-align: center;\">\n<img src=\"https://drive.google.com/uc?export=view&id=19ZnyOatygiAWOif1eANTm69ahLeW3GER\" style='width: 500px; height: 500px;'>\n</p>\n<p style=\"text-align: right\">Generated by Open Journey</p>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"top\"></a>\n# <div style=\"padding:20px;color:white;margin:0;font-size:35px;font-family:verdana;text-align:center;display:fill;border-radius:40px;background-color:#5236A8;overflow:hidden\"><b>Table of Contents</b></div>\n\n<div style=\"background-color:aliceblue; padding:30px; font-size:15px;color:#034914\">\n    \n* [1. Introduction](#1)\n* [2. Data Exploration](#2)\n    - [2.1 Import libraries](#2.1)\n    - [2.2 Load data](#2.2)\n    - [2.3 Take a first look at the data](#2.3)\n    - [2.4 How many folders are in train audio?](#2.4)\n    - [2.5 How many bird songs are in total?](#2.5)\n    - [2.6 Listen a few bird song samples](#2.6)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"1\"></a>\n# <div style=\"padding:20px;color:white;margin:0;font-size:35px;font-family:verdana;text-align:center;display:fill;border-radius:40px;background-color:#5236A8;overflow:hidden\"><b>1. Introduction </b></div>\n\n\n<div style=\"background-color:aliceblue; padding:30px; font-size:15px;color:#034914\">\n    \n  * Goal: The goal of this Kaggle competition is to use machine learning to identify Eastern African bird species by their calls. The objective is to develop computational solutions that can process continuous audio data and recognize species by their calls in order to aid conservation efforts in Africa.\n  * Dataset: The training data consists of short recordings of individual bird calls generously uploaded by users of xenocanto.org, while the test data is made up of 10-minute long recordings in ogg audio format. A sample submission and metadata file containing relevant fields such as primary_label, latitude, longitude, and author are also provided.\n  * Evaluation Metric: The evaluation metric for this contest is padded cmAP, a derivative of the macro-averaged average precision score. This metric supports accepting predictions for species with zero true positive labels and reduces the impact of species with very few positive labels by padding each submission and solution with five rows of true positives.\n  * Challenge: The challenge for participants is to train reliable classifiers with limited training data, as accurate solutions could enable more comprehensive monitoring of bird populations for conservation purposes. This year, the competition also requires models to complete inference in a more constrained time frame to facilitate on-the-ground conservation efforts where efficiency is at a premium.\n  * Significance: Identifying birds by sound is important for monitoring bird populations for conservation purposes as it allows for larger spatial scales to be sampled with higher temporal resolution. This approach also enables conservationists to explore the relationship between restoration interventions and biodiversity in depth, making it an important tool for conservation efforts.\n    \n Important note - **GPU is disabled, you may submmit only CPU notebook with <= 90 minutes run-time**","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2\"></a>\n# <div style=\"padding:20px;color:white;margin:0;font-size:35px;font-family:verdana;text-align:center;display:fill;border-radius:40px;background-color:#5236A8;overflow:hidden\"><b>2. Data Exploration </b></div>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2.1\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.1 Import libraries</h2></div>","metadata":{}},{"cell_type":"code","source":"from pathlib import Path\n\nimport pandas as pd\nimport numpy as np\nimport librosa\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom IPython.display import Audio","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:38:04.366362Z","iopub.execute_input":"2023-03-08T08:38:04.366877Z","iopub.status.idle":"2023-03-08T08:38:04.767551Z","shell.execute_reply.started":"2023-03-08T08:38:04.366834Z","shell.execute_reply":"2023-03-08T08:38:04.766454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.2\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.2 Load data</h2></div>","metadata":{}},{"cell_type":"code","source":"data_path = Path(\"/kaggle/input/birdclef-2023\")\n\ntrain_metadata = pd.read_csv(data_path / \"train_metadata.csv\")\nsample_submission = pd.read_csv(data_path / \"sample_submission.csv\")\nebird_taxonomy_v2021 = pd.read_csv(data_path / \"eBird_Taxonomy_v2021.csv\")\n\ntrain_audio = data_path / \"train_audio\"\ntest_soundscapes = data_path / \"test_soundscapes\"","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:34:58.615959Z","iopub.execute_input":"2023-03-08T08:34:58.616564Z","iopub.status.idle":"2023-03-08T08:34:58.800625Z","shell.execute_reply.started":"2023-03-08T08:34:58.616514Z","shell.execute_reply":"2023-03-08T08:34:58.799358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.3\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.3 Take a first look at the data</h2></div>","metadata":{}},{"cell_type":"markdown","source":"First of all, let's take a look at the tables of this dataset","metadata":{}},{"cell_type":"code","source":"train_metadata","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:02.108179Z","iopub.execute_input":"2023-03-08T08:35:02.109823Z","iopub.status.idle":"2023-03-08T08:35:02.151044Z","shell.execute_reply.started":"2023-03-08T08:35:02.109726Z","shell.execute_reply":"2023-03-08T08:35:02.147975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:02.393988Z","iopub.execute_input":"2023-03-08T08:35:02.394822Z","iopub.status.idle":"2023-03-08T08:35:02.424504Z","shell.execute_reply.started":"2023-03-08T08:35:02.394748Z","shell.execute_reply":"2023-03-08T08:35:02.423323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ebird_taxonomy_v2021","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:02.744946Z","iopub.execute_input":"2023-03-08T08:35:02.745680Z","iopub.status.idle":"2023-03-08T08:35:02.772813Z","shell.execute_reply.started":"2023-03-08T08:35:02.745628Z","shell.execute_reply":"2023-03-08T08:35:02.770812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"And now, we can take a look at the `train_audio` folder. That's where all train bird songs are stored","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2.4\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.4 How many folders are in train audio?</h2></div>","metadata":{}},{"cell_type":"code","source":"train_folders = train_audio.rglob('')\nprint(len(list(train_folders)))","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:06.530042Z","iopub.execute_input":"2023-03-08T08:35:06.530513Z","iopub.status.idle":"2023-03-08T08:35:06.738700Z","shell.execute_reply.started":"2023-03-08T08:35:06.530477Z","shell.execute_reply":"2023-03-08T08:35:06.736761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.5\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.5 How many bird songs are in total?</h2></div>","metadata":{}},{"cell_type":"code","source":"bird_songs = train_audio.glob('**/*.*')\nprint(len(list(bird_songs)))","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:06.888104Z","iopub.execute_input":"2023-03-08T08:35:06.889371Z","iopub.status.idle":"2023-03-08T08:35:07.336550Z","shell.execute_reply.started":"2023-03-08T08:35:06.889320Z","shell.execute_reply":"2023-03-08T08:35:07.335011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Same number, as rows in train_metadata","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2.6\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.6 Listen a few bird song samples</h2></div>","metadata":{}},{"cell_type":"code","source":"def play_audio(label, filename):\n    audio_abe, sr_abe = librosa.load(train_audio / label / filename)\n    return Audio(data=audio_abe, rate=sr_abe)","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:10.768542Z","iopub.execute_input":"2023-03-08T08:35:10.768997Z","iopub.status.idle":"2023-03-08T08:35:10.775727Z","shell.execute_reply.started":"2023-03-08T08:35:10.768961Z","shell.execute_reply":"2023-03-08T08:35:10.774105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_audio(\"abethr1\", \"XC128013.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:11.055395Z","iopub.execute_input":"2023-03-08T08:35:11.055927Z","iopub.status.idle":"2023-03-08T08:35:11.205309Z","shell.execute_reply.started":"2023-03-08T08:35:11.055857Z","shell.execute_reply":"2023-03-08T08:35:11.203643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_audio(\"abhori1\", \"XC120250.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:35:11.276111Z","iopub.execute_input":"2023-03-08T08:35:11.276611Z","iopub.status.idle":"2023-03-08T08:35:11.401752Z","shell.execute_reply.started":"2023-03-08T08:35:11.276572Z","shell.execute_reply":"2023-03-08T08:35:11.400188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2.7\"></a>\n# <div><h2 style=\"font-family: Verdana; font-size: 25px; font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; letter-spacing: 2px; color: #155D07; background-color: #ffffff;\">2.7 Build audio spectrogram</h2></div>","metadata":{}},{"cell_type":"code","source":"def plot_spectrogram(filename):\n    y, sr = librosa.load(train_audio / filename)\n    D = librosa.stft(y)  # STFT of y\n    S_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)\n    fig, ax = plt.subplots()\n    img = librosa.display.specshow(S_db, x_axis='time', y_axis='linear', ax=ax)\n    ax.set(title=f'{filename}')\n    fig.colorbar(img, ax=ax, format=\"%+2.f dB\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:47:51.845894Z","iopub.execute_input":"2023-03-08T08:47:51.846429Z","iopub.status.idle":"2023-03-08T08:47:51.855267Z","shell.execute_reply.started":"2023-03-08T08:47:51.846391Z","shell.execute_reply":"2023-03-08T08:47:51.853964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(\"abethr1/XC128013.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:47:52.075596Z","iopub.execute_input":"2023-03-08T08:47:52.076499Z","iopub.status.idle":"2023-03-08T08:47:54.694125Z","shell.execute_reply.started":"2023-03-08T08:47:52.076449Z","shell.execute_reply":"2023-03-08T08:47:54.693003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(\"abhori1/XC120250.ogg\")","metadata":{"execution":{"iopub.status.busy":"2023-03-08T08:47:54.696056Z","iopub.execute_input":"2023-03-08T08:47:54.696704Z","iopub.status.idle":"2023-03-08T08:47:56.859680Z","shell.execute_reply.started":"2023-03-08T08:47:54.696665Z","shell.execute_reply":"2023-03-08T08:47:56.858390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **📩💻 Updates are on my way. If you like this notebook, feel free to upvote and comment.**","metadata":{}}]}