{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":70203,"databundleVersionId":8068726,"sourceType":"competition"},{"sourceId":170174481,"sourceType":"kernelVersion"}],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nfrom pathlib import Path\n\ndf = pd.read_csv('/kaggle/input/bc24-eda/train_metadata_with_num_frames.csv')\n\nTRAIN_PATH = Path('/kaggle/input/birdclef-2024/train_audio')\n\nSAMPLE_RATE = 32_000\nWINDOW = 5*SAMPLE_RATE","metadata":{"execution":{"iopub.status.busy":"2024-04-18T05:45:54.148724Z","iopub.execute_input":"2024-04-18T05:45:54.149256Z","iopub.status.idle":"2024-04-18T05:45:54.358196Z","shell.execute_reply.started":"2024-04-18T05:45:54.149212Z","shell.execute_reply":"2024-04-18T05:45:54.356761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torchaudio\nfrom tqdm import tqdm\n\nfrom joblib import Parallel, delayed\nimport os\n\ndef get_max(filename):\n    audio = torchaudio.load(TRAIN_PATH / filename)[0][0]\n    return audio[:WINDOW].max(), audio[-WINDOW:].max()\n\n\nmax_volumnes = Parallel(n_jobs=os.cpu_count())(\n    delayed(get_max)(filename) \n    for filename in tqdm(df.filename)\n)","metadata":{"execution":{"iopub.status.busy":"2024-04-18T05:45:54.360483Z","iopub.execute_input":"2024-04-18T05:45:54.361004Z","iopub.status.idle":"2024-04-18T05:54:11.264917Z","shell.execute_reply.started":"2024-04-18T05:45:54.360966Z","shell.execute_reply":"2024-04-18T05:54:11.263519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['first5s_max_volume'] = [a.item() for a, b in max_volumnes]\ndf['last5s_max_volume'] = [b.item() for a, b in max_volumnes]\nimport numpy as np\ndf['max_volume'] = np.max([np.array(df.first5s_max_volume), np.array(df.last5s_max_volume)], 0)\ndf.to_csv('train_metadata_with_volumes.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-18T06:03:57.243942Z","iopub.execute_input":"2024-04-18T06:03:57.244506Z","iopub.status.idle":"2024-04-18T06:03:58.044501Z","shell.execute_reply.started":"2024-04-18T06:03:57.244462Z","shell.execute_reply":"2024-04-18T06:03:58.042570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.read_csv('train_metadata_with_volumes.csv')","metadata":{"execution":{"iopub.status.busy":"2024-04-18T06:03:58.819661Z","iopub.execute_input":"2024-04-18T06:03:58.820103Z","iopub.status.idle":"2024-04-18T06:03:59.070042Z","shell.execute_reply.started":"2024-04-18T06:03:58.820068Z","shell.execute_reply":"2024-04-18T06:03:59.068260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.first5s_max_volume.hist(bins=1000)","metadata":{"execution":{"iopub.status.busy":"2024-04-18T05:54:37.613637Z","iopub.execute_input":"2024-04-18T05:54:37.614410Z","iopub.status.idle":"2024-04-18T05:54:40.076088Z","shell.execute_reply.started":"2024-04-18T05:54:37.614350Z","shell.execute_reply":"2024-04-18T05:54:40.074524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.last5s_max_volume.hist(bins=1000)","metadata":{"execution":{"iopub.status.busy":"2024-04-18T05:54:53.952425Z","iopub.execute_input":"2024-04-18T05:54:53.952863Z","iopub.status.idle":"2024-04-18T05:54:56.066209Z","shell.execute_reply.started":"2024-04-18T05:54:53.952830Z","shell.execute_reply":"2024-04-18T05:54:56.064212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.max_volume.hist(bins=1000)","metadata":{"execution":{"iopub.status.busy":"2024-04-18T05:58:12.014360Z","iopub.execute_input":"2024-04-18T05:58:12.014885Z","iopub.status.idle":"2024-04-18T05:58:14.540514Z","shell.execute_reply.started":"2024-04-18T05:58:12.014849Z","shell.execute_reply":"2024-04-18T05:58:14.539204Z"},"trusted":true},"execution_count":null,"outputs":[]}]}