{"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":"![](https://wallpapercave.com/wp/wp7039642.jpg)\n# BirdCLEF 2022 : Introduction\n---\nIn this notebook we will iterate through the data and file for the first time and find some tabular insights and find whether they play and specific role predicting.\n\n**This is the first of the 3 notebooks which contains the introduction towards given data.\nOn the next notebooks model training and preparation will be done .**","metadata":{"execution":{"iopub.status.busy":"2022-02-28T04:19:41.859751Z","iopub.execute_input":"2022-02-28T04:19:41.86028Z","iopub.status.idle":"2022-02-28T04:19:41.889709Z","shell.execute_reply.started":"2022-02-28T04:19:41.86016Z","shell.execute_reply":"2022-02-28T04:19:41.88819Z"}}},{"cell_type":"markdown","source":"# Libraries","metadata":{}},{"cell_type":"code","source":"from glob import glob\nimport json\nimport numpy as np\nimport os\nimport pandas as pd\nfrom termcolor import cprint\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.309492Z","iopub.execute_input":"2022-02-28T16:41:46.310089Z","iopub.status.idle":"2022-02-28T16:41:46.317709Z","shell.execute_reply.started":"2022-02-28T16:41:46.310036Z","shell.execute_reply":"2022-02-28T16:41:46.317021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Source of the files and data","metadata":{}},{"cell_type":"code","source":"train_base_path = \"../input/birdclef-2022/train_metadata.csv\"\ntest_base_path = \"../input/birdclef-2022/test.csv\"\nsample_submission_base_path = \"../input/birdclef-2022/sample_submission.csv\"\nbird_taxonomy_base_path = \"../input/birdclef-2022/eBird_Taxonomy_v2021.csv\"\nlabels_base_path = \"../input/birdclef-2022/scored_birds.json\"\ntrain_dir = \"../input/birdclef-2022/train_audio\"\ntest_dir = \"../input/birdclef-2022/test_soundscapes\"","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.319423Z","iopub.execute_input":"2022-02-28T16:41:46.319818Z","iopub.status.idle":"2022-02-28T16:41:46.331641Z","shell.execute_reply.started":"2022-02-28T16:41:46.319781Z","shell.execute_reply":"2022-02-28T16:41:46.330826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading Data","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(train_base_path)\ntest_df = pd.read_csv(test_base_path)\nsamp_sub_df = pd.read_csv(sample_submission_base_path)\nbird_details_df = pd.read_csv(bird_taxonomy_base_path)\nlabels = json.load(open(labels_base_path, \"r\"))","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.333071Z","iopub.execute_input":"2022-02-28T16:41:46.333349Z","iopub.status.idle":"2022-02-28T16:41:46.476137Z","shell.execute_reply.started":"2022-02-28T16:41:46.333318Z","shell.execute_reply":"2022-02-28T16:41:46.475205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Iterating through train metadata :\n\nWe will take an overview of the train metadata first then we will jump to further insights.","metadata":{}},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.477470Z","iopub.execute_input":"2022-02-28T16:41:46.477721Z","iopub.status.idle":"2022-02-28T16:41:46.498200Z","shell.execute_reply.started":"2022-02-28T16:41:46.477690Z","shell.execute_reply":"2022-02-28T16:41:46.496945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see the train data is mostly filled with naming columns which will not help us to retrieve any knowledge of the species.\nThe primary important features should be -\n#### 1. primary_label : \n        It represents the target feature.\n#### 2. type :\n        It will help us to determine te nature of calls\n#### 3. latitude :\n        It will help us retreieving geographic location.\n#### 4. longitude :\n        It will help us retreieving geographic location.\n#### 5. rating :\n        Quality of the recording will help us analyzing the final products as quality may differ in training and testing data.\n#### 6. time :\n        It will help us understanding the birds up time , which can be a contributing factor to model building.\n#### 7. filename :\n        It will act as source for the records of the row data.","metadata":{}},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.500825Z","iopub.execute_input":"2022-02-28T16:41:46.501135Z","iopub.status.idle":"2022-02-28T16:41:46.537368Z","shell.execute_reply.started":"2022-02-28T16:41:46.501102Z","shell.execute_reply":"2022-02-28T16:41:46.536427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From the train metadata we can see that most of the features are object type and useless for final prediction.","metadata":{}},{"cell_type":"markdown","source":"#### Iterating through test metadata :\n\nFrom test metadata we can found what features should be the main ones for prediction.","metadata":{}},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.539183Z","iopub.execute_input":"2022-02-28T16:41:46.539447Z","iopub.status.idle":"2022-02-28T16:41:46.551728Z","shell.execute_reply.started":"2022-02-28T16:41:46.539414Z","shell.execute_reply":"2022-02-28T16:41:46.550813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see in test metadat there's a column named **end_time** which will describe the last 5 second recording of the bird which should be predicted.","metadata":{}},{"cell_type":"code","source":"test_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.553343Z","iopub.execute_input":"2022-02-28T16:41:46.553796Z","iopub.status.idle":"2022-02-28T16:41:46.572980Z","shell.execute_reply.started":"2022-02-28T16:41:46.553766Z","shell.execute_reply":"2022-02-28T16:41:46.571897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In the test metadata we can see most of the features aren't present like the location of the recording which could be beneficial for primitive model training and predicting.","metadata":{}},{"cell_type":"code","source":"samp_sub_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.574326Z","iopub.execute_input":"2022-02-28T16:41:46.574577Z","iopub.status.idle":"2022-02-28T16:41:46.590137Z","shell.execute_reply.started":"2022-02-28T16:41:46.574545Z","shell.execute_reply":"2022-02-28T16:41:46.589032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The sample submission holds only the test id and the prediction .","metadata":{}},{"cell_type":"code","source":"samp_sub_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.591625Z","iopub.execute_input":"2022-02-28T16:41:46.592041Z","iopub.status.idle":"2022-02-28T16:41:46.609199Z","shell.execute_reply.started":"2022-02-28T16:41:46.592002Z","shell.execute_reply":"2022-02-28T16:41:46.608332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Approach :\n\nThe approach should be as follows -\n\n            1. Create and train a NN model and train it on the training data.\n            2. Trim and prepare the testing data and predict the model over it.\n            3. Check if the one-hot coded representation really predicts the output class.\n            4. Assign True of False as it should be.","metadata":{}},{"cell_type":"code","source":"bird_details_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.610609Z","iopub.execute_input":"2022-02-28T16:41:46.610836Z","iopub.status.idle":"2022-02-28T16:41:46.632753Z","shell.execute_reply.started":"2022-02-28T16:41:46.610809Z","shell.execute_reply":"2022-02-28T16:41:46.631897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_details_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.634122Z","iopub.execute_input":"2022-02-28T16:41:46.634374Z","iopub.status.idle":"2022-02-28T16:41:46.665835Z","shell.execute_reply.started":"2022-02-28T16:41:46.634337Z","shell.execute_reply":"2022-02-28T16:41:46.665035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The details of the bird may lead us to find some key points which will be helpful preparing the model.","metadata":{}},{"cell_type":"code","source":"# Scored birds\nlabels","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.666856Z","iopub.execute_input":"2022-02-28T16:41:46.667106Z","iopub.status.idle":"2022-02-28T16:41:46.673681Z","shell.execute_reply.started":"2022-02-28T16:41:46.667077Z","shell.execute_reply":"2022-02-28T16:41:46.672633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.primary_label.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.675325Z","iopub.execute_input":"2022-02-28T16:41:46.675787Z","iopub.status.idle":"2022-02-28T16:41:46.686998Z","shell.execute_reply.started":"2022-02-28T16:41:46.675741Z","shell.execute_reply":"2022-02-28T16:41:46.686427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's check throuh the primary label of the birds which will be our target feature.","metadata":{}},{"cell_type":"code","source":"train_df.primary_label.unique()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.690322Z","iopub.execute_input":"2022-02-28T16:41:46.690754Z","iopub.status.idle":"2022-02-28T16:41:46.698757Z","shell.execute_reply.started":"2022-02-28T16:41:46.690724Z","shell.execute_reply":"2022-02-28T16:41:46.697953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Also checking the secondary level as it might contain any relevant data or not.","metadata":{}},{"cell_type":"code","source":"train_df.secondary_labels.apply(lambda x: len(x)).unique()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.699841Z","iopub.execute_input":"2022-02-28T16:41:46.700105Z","iopub.status.idle":"2022-02-28T16:41:46.720798Z","shell.execute_reply.started":"2022-02-28T16:41:46.700064Z","shell.execute_reply":"2022-02-28T16:41:46.720204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Looks like it is not containing any similar fashion, so moving from it.","metadata":{}},{"cell_type":"markdown","source":"#### Calls of the birds :\n\nThe calls of thee birds will help us to determine several type of speech variations of a single species.","metadata":{}},{"cell_type":"code","source":"def call_extractor(data):\n    data = data[1:-1]\n    data = pd.Series(data.split(\", \"))\n    return data.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.722704Z","iopub.execute_input":"2022-02-28T16:41:46.723312Z","iopub.status.idle":"2022-02-28T16:41:46.730547Z","shell.execute_reply.started":"2022-02-28T16:41:46.723267Z","shell.execute_reply":"2022-02-28T16:41:46.729683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_calls = train_df[\"type\"].apply(lambda x : call_extractor(x)).tolist()\ncalls = []\nfor call_list in all_calls:\n    for call in call_list:\n        calls.append(call)\nunique_calls = pd.Series(calls).value_counts().index\nprint(\"Total unique calls : {}\".format(\n                                len(unique_calls)))\nunique_calls[:15]","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:46.732063Z","iopub.execute_input":"2022-02-28T16:41:46.732526Z","iopub.status.idle":"2022-02-28T16:41:48.049758Z","shell.execute_reply.started":"2022-02-28T16:41:46.732484Z","shell.execute_reply":"2022-02-28T16:41:48.049001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see there are different type of calls, so the approach to update it will be to only use the most abundant calls for training, otherwise it will ruin the training metrics.","metadata":{}},{"cell_type":"markdown","source":"# Exploratory Data Analysis :\n\nLet's visualize and try to find if there's any pattern of the features.","metadata":{}},{"cell_type":"markdown","source":"#### Importing libraries for visualization.","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:48.051208Z","iopub.execute_input":"2022-02-28T16:41:48.051701Z","iopub.status.idle":"2022-02-28T16:41:48.055872Z","shell.execute_reply.started":"2022-02-28T16:41:48.051659Z","shell.execute_reply":"2022-02-28T16:41:48.055019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# global location of the species\nunique_labels = train_df.primary_label.unique()\nplt.figure(figsize=(20,6))\nfor label in unique_labels:\n    temp_df = train_df[train_df.primary_label == label]\n    plt.scatter(temp_df.longitude, temp_df.latitude)\nplt.xlabel(\"longitude\")\nplt.ylabel(\"latitude\")\nplt.title(\"Location Wise Distribution\")\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:48.057464Z","iopub.execute_input":"2022-02-28T16:41:48.057750Z","iopub.status.idle":"2022-02-28T16:41:50.432639Z","shell.execute_reply.started":"2022-02-28T16:41:48.057713Z","shell.execute_reply":"2022-02-28T16:41:50.431889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's check presenceee of the species by their latitude","metadata":{}},{"cell_type":"code","source":"# global location of the species\nunique_labels = train_df.primary_label.unique()\nplt.figure(figsize=(20,6))\nfor label in unique_labels:\n    temp_df = train_df[train_df.primary_label == label]\n    plt.scatter(temp_df.longitude.apply(lambda x: abs(x)), temp_df.latitude)\nplt.xlabel(\"longitude\")\nplt.ylabel(\"latitude\")\nplt.title(\"Location Wise Distribution (Equtorial to Polar region)\")\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:50.434092Z","iopub.execute_input":"2022-02-28T16:41:50.434293Z","iopub.status.idle":"2022-02-28T16:41:52.863861Z","shell.execute_reply.started":"2022-02-28T16:41:50.434268Z","shell.execute_reply":"2022-02-28T16:41:52.862925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's check the ratings of the bird call recording perprimary label.","metadata":{}},{"cell_type":"code","source":"avg_ratings = train_df.groupby(\"primary_label\").agg({\"rating\" : \"mean\"})\nplt.figure(figsize = (20, 6))\nsns.barplot(avg_ratings.index, avg_ratings.rating)\nplt.title(\"Average ratings on specific bird codes\")\nplt.xlabel(\"Bird Codes\")\nplt.ylabel(\"Rating\")\nplt.xticks(rotation = 90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:52.865664Z","iopub.execute_input":"2022-02-28T16:41:52.866207Z","iopub.status.idle":"2022-02-28T16:41:54.918062Z","shell.execute_reply.started":"2022-02-28T16:41:52.866153Z","shell.execute_reply":"2022-02-28T16:41:54.917213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's also check the average call timings of the species.","metadata":{}},{"cell_type":"code","source":"def time_converter(data):\n    try:\n        hour, minute = data.split(\":\")\n        return int(hour)*60 + int(minute)\n    except:\n        return -1\n\ntimings = train_df[[\"primary_label\", \"time\"]].copy()\ntimings[\"time\"] = timings[\"time\"].apply(time_converter)\ntimings = timings[timings[\"time\"] >= 0 ]\navg_timings = timings.groupby(\"primary_label\").agg({\"time\" : \"mean\"})\nplt.figure(figsize = (20, 6))\nsns.barplot(avg_timings.index, avg_timings.time)\nplt.title(\"Average time on specific bird codes records\")\nplt.xlabel(\"Bird Codes\")\nplt.ylabel(\"Recording time\")\nplt.xticks(rotation = 90)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:54.919561Z","iopub.execute_input":"2022-02-28T16:41:54.919857Z","iopub.status.idle":"2022-02-28T16:41:57.184193Z","shell.execute_reply.started":"2022-02-28T16:41:54.919818Z","shell.execute_reply":"2022-02-28T16:41:57.183313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now checking the 3d spatial representation of latitude, longitude and timing so that we can find deeper meanings","metadata":{}},{"cell_type":"code","source":"feature_df = train_df[[\"latitude\", \"longitude\", \"time\", \"primary_label\"]]\nfeature_df.time = feature_df.time.apply(time_converter)\nfeature_df = feature_df[feature_df.time >= 0]\nfeature_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:57.185637Z","iopub.execute_input":"2022-02-28T16:41:57.186110Z","iopub.status.idle":"2022-02-28T16:41:57.221925Z","shell.execute_reply.started":"2022-02-28T16:41:57.186070Z","shell.execute_reply":"2022-02-28T16:41:57.220901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from mpl_toolkits import mplot3d\nfig = plt.figure(figsize=(10,10))\nax = plt.axes(projection='3d')\nX = feature_df.latitude\nY = feature_df.longitude\nZ = feature_df.time\nax.plot_trisurf(X, Y, Z, linewidth=0, antialiased=False)\nax.set_title('surface');\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:57.223219Z","iopub.execute_input":"2022-02-28T16:41:57.223599Z","iopub.status.idle":"2022-02-28T16:41:59.674331Z","shell.execute_reply.started":"2022-02-28T16:41:57.223558Z","shell.execute_reply":"2022-02-28T16:41:59.673407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The target feature count also should be checked as it contributes the most while predicting.","metadata":{}},{"cell_type":"code","source":"target_feature_dist = train_df.primary_label.value_counts()\nplt.figure(figsize = (8, 8))\nplt.pie(target_feature_dist.values, labels= target_feature_dist.index)\nplt.title(\"Target Feature Distribution\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T16:41:59.675846Z","iopub.execute_input":"2022-02-28T16:41:59.676155Z","iopub.status.idle":"2022-02-28T16:42:01.109741Z","shell.execute_reply.started":"2022-02-28T16:41:59.676115Z","shell.execute_reply":"2022-02-28T16:42:01.108936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see the distribution is not well enough to predict all the class similarly.","metadata":{}},{"cell_type":"markdown","source":"# Record Insights :\n---\nNow it's time to jump inside the recordings.","metadata":{}},{"cell_type":"code","source":"import torch\nimport torchaudio\nfrom torchaudio.transforms import MelSpectrogram\nimport random\nrandom.seed(42)\ntorchaudio.set_audio_backend(\"sox_io\")","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:00.572450Z","iopub.execute_input":"2022-02-28T17:13:00.572923Z","iopub.status.idle":"2022-02-28T17:13:00.579228Z","shell.execute_reply.started":"2022-02-28T17:13:00.572879Z","shell.execute_reply":"2022-02-28T17:13:00.578356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_ogg_file_base_path = \"../input/birdclef-2022/train_audio/barpet/XC441955.ogg\"\nwaveform, sample_rate = torchaudio.load(sample_ogg_file_base_path)\nprint(\"Sample rate : {}\".format(sample_rate))\nprint(\"Shape of waveform : {}\".format(waveform.shape))","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:00.580921Z","iopub.execute_input":"2022-02-28T17:13:00.581182Z","iopub.status.idle":"2022-02-28T17:13:00.608367Z","shell.execute_reply.started":"2022-02-28T17:13:00.581153Z","shell.execute_reply":"2022-02-28T17:13:00.607380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20, 6))\nplt.scatter(range(waveform.shape[1]), waveform.reshape(-1), s = 1)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Frequency\")\nplt.title(\"Sample audio wave propagation\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:00.610596Z","iopub.execute_input":"2022-02-28T17:13:00.611622Z","iopub.status.idle":"2022-02-28T17:13:01.901370Z","shell.execute_reply.started":"2022-02-28T17:13:00.611570Z","shell.execute_reply":"2022-02-28T17:13:01.900438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's see any pattern is there for every single species type","metadata":{}},{"cell_type":"code","source":"melsp = MelSpectrogram(sample_rate = 32000)","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:01.903262Z","iopub.execute_input":"2022-02-28T17:13:01.903819Z","iopub.status.idle":"2022-02-28T17:13:01.911014Z","shell.execute_reply.started":"2022-02-28T17:13:01.903765Z","shell.execute_reply":"2022-02-28T17:13:01.910309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def pad_or_truncate(waveform, max_sample_len):\n    if waveform.shape[0] > max_sample_len:\n        return waveform[:max_sample_len]\n    else:\n        pad_length = (max_sample_len - waveform.shape[0]) // 2\n        left_pad = right_pad = torch.zeros(pad_length)\n        return torch.cat([left_pad, waveform, right_pad], axis = 0)\n        \n        \ndef form_audio_curve(directory, num_samples = 3, max_sample_len = 60000):\n    file_paths = glob(f\"{directory}/*ogg\")\n    #print(file_paths[:num_samples])\n    random.shuffle(file_paths)\n    plt.figure(figsize = (20, 6))\n    for index, path in enumerate(file_paths[:num_samples]):\n        waveform, _ = torchaudio.load(path)\n        print(waveform.shape)\n        waveform = pad_or_truncate(waveform[0], max_sample_len)\n        plt.plot(waveform, label = f\"audio{index+1}\")\n    plt.legend()\n    plt.show()\nform_audio_curve(directory = \"../input/birdclef-2022/train_audio/buwtea\")","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:01.912679Z","iopub.execute_input":"2022-02-28T17:13:01.913213Z","iopub.status.idle":"2022-02-28T17:13:03.853255Z","shell.execute_reply.started":"2022-02-28T17:13:01.913176Z","shell.execute_reply":"2022-02-28T17:13:03.852450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for folder in os.listdir(train_dir):\n    folder_path = os.path.join(train_dir, folder)\n    form_audio_curve(directory = folder_path)","metadata":{"execution":{"iopub.status.busy":"2022-02-28T17:13:03.854383Z","iopub.execute_input":"2022-02-28T17:13:03.854627Z","iopub.status.idle":"2022-02-28T17:18:57.136856Z","shell.execute_reply.started":"2022-02-28T17:13:03.854600Z","shell.execute_reply":"2022-02-28T17:18:57.135891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Visiting every single directory elements , it is sure that most of them follow a periodic effect, but some are very robust and randomize.","metadata":{}},{"cell_type":"markdown","source":"## Thanks for visiting!\n## Do STAR if yo like it!","metadata":{}}]}