{"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 pandas as pd\nimport os\nimport librosa\nimport torch\nfrom torch.utils.data import DataLoader","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-08T17:29:47.322202Z","iopub.execute_input":"2022-04-08T17:29:47.323629Z","iopub.status.idle":"2022-04-08T17:29:52.421043Z","shell.execute_reply.started":"2022-04-08T17:29:47.323349Z","shell.execute_reply":"2022-04-08T17:29:52.420281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pwd","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:29:52.423282Z","iopub.execute_input":"2022-04-08T17:29:52.423821Z","iopub.status.idle":"2022-04-08T17:29:53.244812Z","shell.execute_reply.started":"2022-04-08T17:29:52.423755Z","shell.execute_reply":"2022-04-08T17:29:53.24353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT = '/kaggle/input/birdsong-recognition/'\nos.listdir(ROOT)","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:29:53.246698Z","iopub.execute_input":"2022-04-08T17:29:53.247028Z","iopub.status.idle":"2022-04-08T17:29:53.259485Z","shell.execute_reply.started":"2022-04-08T17:29:53.246991Z","shell.execute_reply":"2022-04-08T17:29:53.258564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(os.path.join(ROOT, 'train.csv'))[['ebird_code', 'filename', 'duration']]\ndf['path'] = ROOT + 'train_audio/' + df['ebird_code'] + '/'+ df['filename']\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:29:53.262021Z","iopub.execute_input":"2022-04-08T17:29:53.262741Z","iopub.status.idle":"2022-04-08T17:29:54.021181Z","shell.execute_reply.started":"2022-04-08T17:29:53.262698Z","shell.execute_reply":"2022-04-08T17:29:54.020197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SR = 32000 # sampling rate\nN_MELS = 128\nFRAC = 0.2\nbatch_size = 8","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:29:54.02267Z","iopub.execute_input":"2022-04-08T17:29:54.023636Z","iopub.status.idle":"2022-04-08T17:29:54.029363Z","shell.execute_reply.started":"2022-04-08T17:29:54.023589Z","shell.execute_reply":"2022-04-08T17:29:54.028122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for _, row in df.iterrows():\n    audio, sample_rate = librosa.load(row['path'],\n                                     sr=SR,\n                                     mono=True,\n                                     offset=0.0,\n                                     duration=row['duration'],\n                                     res_type='kaiser_fast')\n#     print(audio.shape)\n    mels = librosa.feature.melspectrogram(y=audio, sr=SR, n_mels=N_MELS)\n#     print(mels.shape)","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:30:36.01416Z","iopub.execute_input":"2022-04-08T17:30:36.014531Z","iopub.status.idle":"2022-04-08T17:33:38.270914Z","shell.execute_reply.started":"2022-04-08T17:30:36.014494Z","shell.execute_reply":"2022-04-08T17:33:38.269616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df = df.sample(frac=1).reset_index(drop=True) # why\ntrain_len = int(len(df) * (1-FRAC))\ntrain_df = df.iloc[:train_len]\nvalid_df = df.iloc[train_len:]\ntrain_df.shape, valid_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:30:30.457486Z","iopub.status.idle":"2022-04-08T17:30:30.457991Z","shell.execute_reply.started":"2022-04-08T17:30:30.457725Z","shell.execute_reply":"2022-04-08T17:30:30.457753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_loader = torch.utils.data.DataLoader(train_df,\n                                     batch_size=batch_size,\n                                     num_workers=4,\n                                     shuffle=True,\n                                     drop_last=True)\n\nvalid_loader = torch.utils.data.DataLoader(valid_df,\n                                     batch_size = batch_size,\n                                     num_workers=4,\n                                     shuffle=True,\n                                     drop_last=True)\n\nlen(train_loader), len(valid_loader)","metadata":{"execution":{"iopub.status.busy":"2022-04-08T17:30:30.459633Z","iopub.status.idle":"2022-04-08T17:30:30.460303Z","shell.execute_reply.started":"2022-04-08T17:30:30.460035Z","shell.execute_reply":"2022-04-08T17:30:30.460065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model","metadata":{}},{"cell_type":"markdown","source":"On va faire un convertisseur vers 2D comme vue dans la vidéo avec Conv2D  ","metadata":{}},{"cell_type":"code","source":"nn.e","metadata":{},"execution_count":null,"outputs":[]}]}