{"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"}],"dockerImageVersionId":30698,"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\nimport torch\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\nimport torchaudio\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-04T16:08:18.190112Z","iopub.execute_input":"2024-05-04T16:08:18.190517Z","iopub.status.idle":"2024-05-04T16:08:24.488517Z","shell.execute_reply.started":"2024-05-04T16:08:18.190484Z","shell.execute_reply":"2024-05-04T16:08:24.487225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/birdclef-2024/train_metadata.csv')\n\nTRAIN_PATH = Path('/kaggle/input/birdclef-2024/train_audio')\n\nSAMPLE_RATE = 32_000\nWINDOW = 20*SAMPLE_RATE","metadata":{"execution":{"iopub.status.busy":"2024-05-04T16:10:14.268146Z","iopub.execute_input":"2024-05-04T16:10:14.268553Z","iopub.status.idle":"2024-05-04T16:10:14.389514Z","shell.execute_reply.started":"2024-05-04T16:10:14.268526Z","shell.execute_reply":"2024-05-04T16:10:14.388390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# helpers for displaying bird recordings for manual inspection\ncompute_melspec = torchaudio.transforms.MelSpectrogram(\n    sample_rate=SAMPLE_RATE,\n    n_mels=128,\n    n_fft=2048, \n    hop_length=512,\n)\n\npower_to_db = torchaudio.transforms.AmplitudeToDB(\n    stype=\"power\",\n    top_db=80.0,\n)\n\ndef show_audiofile(filename):\n    audio = torchaudio.load(TRAIN_PATH / filename)[0][0][:WINDOW]\n    plt.axis('off')\n    plt.title(filename)\n    plt.imshow(power_to_db(compute_melspec(audio)))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T16:10:14.457680Z","iopub.execute_input":"2024-05-04T16:10:14.458338Z","iopub.status.idle":"2024-05-04T16:10:14.465099Z","shell.execute_reply.started":"2024-05-04T16:10:14.458299Z","shell.execute_reply":"2024-05-04T16:10:14.464288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a, b = 'woosan/XC587076.ogg', 'woosan/XC578599.ogg'\n\nprint(a, b)\nplt.figure(figsize=(12, 5))\nplt.subplot(211)\nshow_audiofile(a)\nplt.subplot(212)\nshow_audiofile(b)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-04T16:10:14.631498Z","iopub.execute_input":"2024-05-04T16:10:14.632128Z","iopub.status.idle":"2024-05-04T16:10:15.424386Z","shell.execute_reply.started":"2024-05-04T16:10:14.632095Z","shell.execute_reply":"2024-05-04T16:10:15.422965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}