{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nimport tensorflow_io as tfio\nfrom keras.models import Sequential\nfrom keras.layers import Dense, Conv2D, Flatten\nfrom itertools import groupby\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-23T08:25:10.533115Z","iopub.execute_input":"2023-09-23T08:25:10.533402Z","iopub.status.idle":"2023-09-23T08:25:10.541664Z","shell.execute_reply.started":"2023-09-23T08:25:10.533372Z","shell.execute_reply":"2023-09-23T08:25:10.540759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CAPUCHIN_FILE = os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Capuchinbird_Clips','XC3776-3.wav')\nNOT_CAPUCHIN_FILE= os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Not_Capuchinbird_Clips','afternoon-birds-song-in-forest-0.wav')","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:19.365299Z","iopub.execute_input":"2023-09-23T08:25:19.365592Z","iopub.status.idle":"2023-09-23T08:25:19.370987Z","shell.execute_reply.started":"2023-09-23T08:25:19.365561Z","shell.execute_reply":"2023-09-23T08:25:19.369903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird1 = '/kaggle/input/birdsong-recognition/train_audio/aldfly/XC135454.mp3'\nbird2 = '/kaggle/input/birdsong-recognition/train_audio/amecro/XC112598.mp3'\n#bird2 = os.path.join('/kaggle/input','birdsong-recognition','train_audio/amecro','XC112598.mp3')","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:21.084173Z","iopub.execute_input":"2023-09-23T08:25:21.085130Z","iopub.status.idle":"2023-09-23T08:25:21.089473Z","shell.execute_reply.started":"2023-09-23T08:25:21.085082Z","shell.execute_reply":"2023-09-23T08:25:21.088633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# CAPUCHIN_FILE","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:22.168643Z","iopub.execute_input":"2023-09-23T08:25:22.169637Z","iopub.status.idle":"2023-09-23T08:25:22.173960Z","shell.execute_reply.started":"2023-09-23T08:25:22.169589Z","shell.execute_reply":"2023-09-23T08:25:22.173001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_wav_16k_mono(filename):\n    file_contents=tf.io.read_file(filename)\n    wav,sample_rate=tf.audio.decode_wav(file_contents,desired_channels=1)\n    wav=tf.squeeze(wav,axis=-1)\n    sample_rate=tf.cast(sample_rate,dtype=tf.int64)\n    wav=tfio.audio.resample(wav,rate_in=sample_rate,rate_out=16000)\n    return wav","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:22.977744Z","iopub.execute_input":"2023-09-23T08:25:22.978042Z","iopub.status.idle":"2023-09-23T08:25:22.984011Z","shell.execute_reply.started":"2023-09-23T08:25:22.978010Z","shell.execute_reply":"2023-09-23T08:25:22.983206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wave=load_wav_16k_mono(CAPUCHIN_FILE)\nnwave=load_wav_16k_mono(NOT_CAPUCHIN_FILE)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:24.527443Z","iopub.execute_input":"2023-09-23T08:25:24.528235Z","iopub.status.idle":"2023-09-23T08:25:27.734548Z","shell.execute_reply.started":"2023-09-23T08:25:24.528198Z","shell.execute_reply":"2023-09-23T08:25:27.733760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import required modules mp3 to wav\nfrom os import path\nfrom pydub import AudioSegment\n  \n# assign files\ninput_file1 = '/kaggle/input/birdsong-recognition/train_audio/aldfly/XC135454.mp3'\noutput_file1 = \"result1.wav\"\ninput_file = '/kaggle/input/birdsong-recognition/train_audio/amecro/XC112598.mp3'\noutput_file = \"result.wav\"\n# convert mp3 file to wav file\nsound1 = AudioSegment.from_mp3(input_file1)\nsound1.export(output_file1, format=\"wav\")\nsound = AudioSegment.from_mp3(input_file)\nsound.export(output_file, format=\"wav\")","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:29.695555Z","iopub.execute_input":"2023-09-23T08:25:29.696169Z","iopub.status.idle":"2023-09-23T08:25:31.040560Z","shell.execute_reply.started":"2023-09-23T08:25:29.696129Z","shell.execute_reply":"2023-09-23T08:25:31.039735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nbirds=[\"amecro\",\"carwre\",\"fiespa\",\"foxspa\",\"pinjay\"]\npath = \"/kaggle/working/\"\nfor i in birds:\n    if not os.path.isdir(path+i):\n        os.mkdir(path+i)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:33.864943Z","iopub.execute_input":"2023-09-23T08:25:33.865254Z","iopub.status.idle":"2023-09-23T08:25:33.871076Z","shell.execute_reply.started":"2023-09-23T08:25:33.865221Z","shell.execute_reply":"2023-09-23T08:25:33.870225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import required modules\nimport os\nfrom os import path\nfrom pydub import AudioSegment\ninput_file = \"/kaggle/input/birdsong-recognition/train_audio/\"\noutput = \"/kaggle/working/\"\n# assign files\nbirds=[\"amecro\",\"carwre\",\"fiespa\",\"foxspa\",\"pinjay\"]\nfor i in birds:\n    for k in os.listdir(input_file+i):\n        output_file = os.path.join(output+i,k.split(\".\")[0]+\".wav\")\n        input_f =  os.path.join(input_file+i,k)\n        # convert mp3 file to wav file\n        sound = AudioSegment.from_mp3(input_f)\n        sound.export(output_file, format=\"wav\")","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:25:35.850842Z","iopub.execute_input":"2023-09-23T08:25:35.851161Z","iopub.status.idle":"2023-09-23T08:28:19.413301Z","shell.execute_reply.started":"2023-09-23T08:25:35.851117Z","shell.execute_reply":"2023-09-23T08:28:19.411876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b1=load_wav_16k_mono(\"/kaggle/working/result1.wav\")\nb2=load_wav_16k_mono(\"/kaggle/working/result.wav\")","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:28:19.415989Z","iopub.execute_input":"2023-09-23T08:28:19.416535Z","iopub.status.idle":"2023-09-23T08:28:20.252525Z","shell.execute_reply.started":"2023-09-23T08:28:19.416495Z","shell.execute_reply":"2023-09-23T08:28:20.251765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(b2)\nplt.plot(b1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:28:34.269223Z","iopub.execute_input":"2023-09-23T08:28:34.269804Z","iopub.status.idle":"2023-09-23T08:28:35.087256Z","shell.execute_reply.started":"2023-09-23T08:28:34.269760Z","shell.execute_reply":"2023-09-23T08:28:35.086518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(b1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:28:36.198052Z","iopub.execute_input":"2023-09-23T08:28:36.198344Z","iopub.status.idle":"2023-09-23T08:28:36.471918Z","shell.execute_reply.started":"2023-09-23T08:28:36.198311Z","shell.execute_reply":"2023-09-23T08:28:36.471169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(wave)\nplt.plot(nwave)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:28:39.174477Z","iopub.execute_input":"2023-09-23T08:28:39.175121Z","iopub.status.idle":"2023-09-23T08:28:39.446347Z","shell.execute_reply.started":"2023-09-23T08:28:39.175081Z","shell.execute_reply":"2023-09-23T08:28:39.445568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# POSITIVE=os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Capuchinbird_Clips')\n# NEGATIVE=os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Not_Capuchinbird_Clips')","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:28:42.405275Z","iopub.execute_input":"2023-09-23T08:28:42.405556Z","iopub.status.idle":"2023-09-23T08:28:42.409238Z","shell.execute_reply.started":"2023-09-23T08:28:42.405524Z","shell.execute_reply":"2023-09-23T08:28:42.408512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird1=os.path.join('/kaggle/working','pinjay')\nbird2=os.path.join('/kaggle/working','amecro')\nbird3=os.path.join('/kaggle/working','carwre')\nbird4=os.path.join('/kaggle/working','fiespa')\nbird5=os.path.join('/kaggle/working','foxspa')","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:29:43.849649Z","iopub.execute_input":"2023-09-23T08:29:43.850430Z","iopub.status.idle":"2023-09-23T08:29:43.855976Z","shell.execute_reply.started":"2023-09-23T08:29:43.850392Z","shell.execute_reply":"2023-09-23T08:29:43.855110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b1=tf.data.Dataset.list_files(bird1+'/*.wav')\nb2=tf.data.Dataset.list_files(bird2+'/*.wav')\nb3=tf.data.Dataset.list_files(bird3+'/*.wav')\nb4=tf.data.Dataset.list_files(bird4+'/*.wav')\nb5=tf.data.Dataset.list_files(bird5+'/*.wav')\n","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:29:48.624849Z","iopub.execute_input":"2023-09-23T08:29:48.625127Z","iopub.status.idle":"2023-09-23T08:29:48.663139Z","shell.execute_reply.started":"2023-09-23T08:29:48.625098Z","shell.execute_reply":"2023-09-23T08:29:48.662289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# b11= tf.data.Dataset.zip((b1,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([0 for i in range(len(b1))])))))\n# b21= tf.data.Dataset.zip((b2,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([1 for i in range(len(b2))])))))\n# b31= tf.data.Dataset.zip((b3,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([2 for i in range(len(b3))])))))\n# b41= tf.data.Dataset.zip((b4,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([3 for i in range(len(b4))])))))\n# b51= tf.data.Dataset.zip((b5,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([4 for i in range(len(b5))])))))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:29:54.901370Z","iopub.execute_input":"2023-09-23T08:29:54.901652Z","iopub.status.idle":"2023-09-23T08:29:54.905623Z","shell.execute_reply.started":"2023-09-23T08:29:54.901622Z","shell.execute_reply":"2023-09-23T08:29:54.904901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b11= tf.data.Dataset.zip((b1,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([[1,0,0,0,0] for i in range(len(b1))])))))\nb21= tf.data.Dataset.zip((b2,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([[0,1,0,0,0] for i in range(len(b2))])))))\nb31= tf.data.Dataset.zip((b3,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([[0,0,1,0,0] for i in range(len(b3))])))))\nb41= tf.data.Dataset.zip((b4,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([[0,0,0,1,0] for i in range(len(b4))])))))\nb51= tf.data.Dataset.zip((b5,tf.data.Dataset.from_tensor_slices(tf.convert_to_tensor(np.array([[0,0,0,0,1] for i in range(len(b5))])))))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:29:59.451918Z","iopub.execute_input":"2023-09-23T08:29:59.452193Z","iopub.status.idle":"2023-09-23T08:29:59.473303Z","shell.execute_reply.started":"2023-09-23T08:29:59.452164Z","shell.execute_reply":"2023-09-23T08:29:59.472538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=(((b11.concatenate(b21)).concatenate(b31)).concatenate(b41)).concatenate(b51)\n","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:01.365094Z","iopub.execute_input":"2023-09-23T08:30:01.365380Z","iopub.status.idle":"2023-09-23T08:30:01.372639Z","shell.execute_reply.started":"2023-09-23T08:30:01.365349Z","shell.execute_reply":"2023-09-23T08:30:01.371783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in data:\n    print(i)\n    break","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:04.076485Z","iopub.execute_input":"2023-09-23T08:30:04.076800Z","iopub.status.idle":"2023-09-23T08:30:04.100190Z","shell.execute_reply.started":"2023-09-23T08:30:04.076767Z","shell.execute_reply":"2023-09-23T08:30:04.099394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:23.738197Z","iopub.execute_input":"2023-09-23T08:30:23.738484Z","iopub.status.idle":"2023-09-23T08:30:23.744835Z","shell.execute_reply.started":"2023-09-23T08:30:23.738453Z","shell.execute_reply":"2023-09-23T08:30:23.744003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pos.as_numpy_iterator().next()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:36.346760Z","iopub.execute_input":"2023-09-23T08:30:36.347066Z","iopub.status.idle":"2023-09-23T08:30:36.351282Z","shell.execute_reply.started":"2023-09-23T08:30:36.347031Z","shell.execute_reply":"2023-09-23T08:30:36.350234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# a=tf.ones(len(neg))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:36.452071Z","iopub.execute_input":"2023-09-23T08:30:36.454253Z","iopub.status.idle":"2023-09-23T08:30:36.457958Z","shell.execute_reply.started":"2023-09-23T08:30:36.454214Z","shell.execute_reply":"2023-09-23T08:30:36.456891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#  positives=tf.data.Dataset.zip((pos,tf.data.Dataset.from_tensor_slices(tf.ones(len(pos)))))\n# # positives=tf.data.Dataset.zip((pos,tf.data.Dataset.from_tensor_slices(1)))\n# negatives=tf.data.Dataset.zip((neg,tf.data.Dataset.from_tensor_slices(tf.zeros(len(neg)))))\n# data=positives.concatenate(negatives)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:36.459919Z","iopub.execute_input":"2023-09-23T08:30:36.460463Z","iopub.status.idle":"2023-09-23T08:30:36.471185Z","shell.execute_reply.started":"2023-09-23T08:30:36.460426Z","shell.execute_reply":"2023-09-23T08:30:36.470236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(positives)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:36.472445Z","iopub.execute_input":"2023-09-23T08:30:36.473096Z","iopub.status.idle":"2023-09-23T08:30:36.481962Z","shell.execute_reply.started":"2023-09-23T08:30:36.473060Z","shell.execute_reply":"2023-09-23T08:30:36.481175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lengths=[]\n# for file in os.listdir(bird1):\n#     tensor_wave=load_wav_16k_mono(os.path.join(bird1,file))\n#     print(tensor_wave)\n#     lengths.append(len(tensor_wave))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:36.553603Z","iopub.execute_input":"2023-09-23T08:30:36.554245Z","iopub.status.idle":"2023-09-23T08:30:36.557914Z","shell.execute_reply.started":"2023-09-23T08:30:36.554206Z","shell.execute_reply":"2023-09-23T08:30:36.557074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lengths=[]\n# for file in os.listdir(os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Capuchinbird_Clips')):\n#     print(file)\n#     tensor_wave=load_wav_16k_mono(os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Parsed_Capuchinbird_Clips',file))\n#     lengths.append(len(tensor_wave))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:42.003426Z","iopub.execute_input":"2023-09-23T08:30:42.003704Z","iopub.status.idle":"2023-09-23T08:30:42.007267Z","shell.execute_reply.started":"2023-09-23T08:30:42.003672Z","shell.execute_reply":"2023-09-23T08:30:42.006537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preprocess(file_path,label):\n    wav=load_wav_16k_mono(file_path)\n    wav=wav[:48000]\n    zero_padding=tf.zeros([48000]-tf.shape(wav),dtype=tf.float32)\n    wav=tf.concat([zero_padding,wav],0)\n    spectrogram=tf.signal.stft(wav,frame_length=320,frame_step=32)\n    spectrogram=tf.abs(spectrogram)\n    spectrogram=tf.expand_dims(spectrogram,axis=2)\n    return spectrogram,label","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:30:42.044648Z","iopub.execute_input":"2023-09-23T08:30:42.045322Z","iopub.status.idle":"2023-09-23T08:30:42.051766Z","shell.execute_reply.started":"2023-09-23T08:30:42.045287Z","shell.execute_reply":"2023-09-23T08:30:42.051022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filepath,label=b11.shuffle(buffer_size=10000).as_numpy_iterator().next()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:11.860279Z","iopub.execute_input":"2023-09-23T08:31:11.860567Z","iopub.status.idle":"2023-09-23T08:31:11.872247Z","shell.execute_reply.started":"2023-09-23T08:31:11.860537Z","shell.execute_reply":"2023-09-23T08:31:11.871473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"spectrogram,label=preprocess(filepath,label)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:11.986131Z","iopub.execute_input":"2023-09-23T08:31:11.986407Z","iopub.status.idle":"2023-09-23T08:31:12.528766Z","shell.execute_reply.started":"2023-09-23T08:31:11.986376Z","shell.execute_reply":"2023-09-23T08:31:12.527935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(30,20))\nplt.imshow(tf.transpose(spectrogram)[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:15.363534Z","iopub.execute_input":"2023-09-23T08:31:15.363854Z","iopub.status.idle":"2023-09-23T08:31:15.700212Z","shell.execute_reply.started":"2023-09-23T08:31:15.363821Z","shell.execute_reply":"2023-09-23T08:31:15.699490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.as_numpy_iterator().next()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:19.703241Z","iopub.execute_input":"2023-09-23T08:31:19.703535Z","iopub.status.idle":"2023-09-23T08:31:19.719452Z","shell.execute_reply.started":"2023-09-23T08:31:19.703502Z","shell.execute_reply":"2023-09-23T08:31:19.718409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=data.map(preprocess)\ndata=data.cache()\ndata=data.shuffle(buffer_size=1000)\ndata=data.batch(8)\ndata=data.prefetch(4)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:19.742179Z","iopub.execute_input":"2023-09-23T08:31:19.742519Z","iopub.status.idle":"2023-09-23T08:31:20.358546Z","shell.execute_reply.started":"2023-09-23T08:31:19.742489Z","shell.execute_reply":"2023-09-23T08:31:20.357770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(data)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:25.931595Z","iopub.execute_input":"2023-09-23T08:31:25.932209Z","iopub.status.idle":"2023-09-23T08:31:25.937809Z","shell.execute_reply.started":"2023-09-23T08:31:25.932160Z","shell.execute_reply":"2023-09-23T08:31:25.937007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in data:\n#     print(i)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:25.969288Z","iopub.execute_input":"2023-09-23T08:31:25.969913Z","iopub.status.idle":"2023-09-23T08:31:25.973814Z","shell.execute_reply.started":"2023-09-23T08:31:25.969878Z","shell.execute_reply":"2023-09-23T08:31:25.973040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=data.take(39)\ntest=data.skip(39).take(18)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:34.602232Z","iopub.execute_input":"2023-09-23T08:31:34.602522Z","iopub.status.idle":"2023-09-23T08:31:34.608750Z","shell.execute_reply.started":"2023-09-23T08:31:34.602489Z","shell.execute_reply":"2023-09-23T08:31:34.608041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samples,labels=train.as_numpy_iterator().next()\nsamples.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:31:34.639102Z","iopub.execute_input":"2023-09-23T08:31:34.639358Z","iopub.status.idle":"2023-09-23T08:32:55.992202Z","shell.execute_reply.started":"2023-09-23T08:31:34.639329Z","shell.execute_reply":"2023-09-23T08:32:55.991434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Conv2D(8,(3,3),activation='relu',input_shape=(1491,257,1)))\nmodel.add(Conv2D(8,(3,3),activation='relu'))\nmodel.add(Conv2D(8,(3,3),activation='relu'))\nmodel.add(Flatten())\nmodel.add(Dense(128,activation='relu'))\nmodel.add(Dense(5,activation='sigmoid'))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:33:56.750946Z","iopub.execute_input":"2023-09-23T08:33:56.751243Z","iopub.status.idle":"2023-09-23T08:33:56.803188Z","shell.execute_reply.started":"2023-09-23T08:33:56.751211Z","shell.execute_reply":"2023-09-23T08:33:56.802439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer ='Adam',loss='categorical_crossentropy',metrics=[tf.keras.metrics.Accuracy(), tf.keras.metrics.Recall(),tf.keras.metrics.Precision()])","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:51:15.492821Z","iopub.execute_input":"2023-09-23T08:51:15.493109Z","iopub.status.idle":"2023-09-23T08:51:15.513694Z","shell.execute_reply.started":"2023-09-23T08:51:15.493078Z","shell.execute_reply":"2023-09-23T08:51:15.512933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:51:19.600175Z","iopub.execute_input":"2023-09-23T08:51:19.600481Z","iopub.status.idle":"2023-09-23T08:51:19.610267Z","shell.execute_reply.started":"2023-09-23T08:51:19.600450Z","shell.execute_reply":"2023-09-23T08:51:19.609361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist=model.fit(train,epochs=30,validation_data=test)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T08:58:08.754292Z","iopub.execute_input":"2023-09-23T08:58:08.756884Z","iopub.status.idle":"2023-09-23T09:02:36.756534Z","shell.execute_reply.started":"2023-09-23T08:58:08.756834Z","shell.execute_reply":"2023-09-23T09:02:36.755769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title('Loss')\nplt.plot(hist.history['loss'],'r')\nplt.plot(hist.history['val_loss'],'b')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:26:41.270619Z","iopub.execute_input":"2023-09-23T09:26:41.271243Z","iopub.status.idle":"2023-09-23T09:26:41.467364Z","shell.execute_reply.started":"2023-09-23T09:26:41.271204Z","shell.execute_reply":"2023-09-23T09:26:41.466612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title('Accuracy')\nplt.plot(hist.history['accuracy'],'r')\nplt.plot(hist.history['val_accuracy'],'b')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:26:47.068403Z","iopub.execute_input":"2023-09-23T09:26:47.068686Z","iopub.status.idle":"2023-09-23T09:26:47.258291Z","shell.execute_reply.started":"2023-09-23T09:26:47.068655Z","shell.execute_reply":"2023-09-23T09:26:47.257584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title('Precision')\nplt.plot(hist.history['precision'],'r')\nplt.plot(hist.history['val_precision'],'b')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:26:50.612414Z","iopub.execute_input":"2023-09-23T09:26:50.613127Z","iopub.status.idle":"2023-09-23T09:26:50.806544Z","shell.execute_reply.started":"2023-09-23T09:26:50.613092Z","shell.execute_reply":"2023-09-23T09:26:50.805842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist.history.keys()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:26:57.007290Z","iopub.execute_input":"2023-09-23T09:26:57.007993Z","iopub.status.idle":"2023-09-23T09:26:57.013413Z","shell.execute_reply.started":"2023-09-23T09:26:57.007955Z","shell.execute_reply":"2023-09-23T09:26:57.012651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.title('Recall')\nplt.plot(hist.history['recall'],'r')\nplt.plot(hist.history['val_recall'],'b')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:26:58.768552Z","iopub.execute_input":"2023-09-23T09:26:58.769353Z","iopub.status.idle":"2023-09-23T09:26:58.977295Z","shell.execute_reply.started":"2023-09-23T09:26:58.769313Z","shell.execute_reply":"2023-09-23T09:26:58.976577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test,y_test=test.as_numpy_iterator().next()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:08.890562Z","iopub.execute_input":"2023-09-23T09:27:08.891148Z","iopub.status.idle":"2023-09-23T09:27:09.029859Z","shell.execute_reply.started":"2023-09-23T09:27:08.891109Z","shell.execute_reply":"2023-09-23T09:27:09.029050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:09.334679Z","iopub.execute_input":"2023-09-23T09:27:09.335430Z","iopub.status.idle":"2023-09-23T09:27:09.350373Z","shell.execute_reply.started":"2023-09-23T09:27:09.335392Z","shell.execute_reply":"2023-09-23T09:27:09.349561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:09.413511Z","iopub.execute_input":"2023-09-23T09:27:09.414140Z","iopub.status.idle":"2023-09-23T09:27:09.419823Z","shell.execute_reply.started":"2023-09-23T09:27:09.414104Z","shell.execute_reply":"2023-09-23T09:27:09.419053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat=model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:21.036808Z","iopub.execute_input":"2023-09-23T09:27:21.037747Z","iopub.status.idle":"2023-09-23T09:27:21.272105Z","shell.execute_reply.started":"2023-09-23T09:27:21.037674Z","shell.execute_reply":"2023-09-23T09:27:21.271005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_list = []\nfor x in y_hat : \n    temp = list(x)\n    ind = temp.index(max(temp))\n    test_list.append([0 if i!=ind else 1 for i in range(5)])\nprint(test_list)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:23.220809Z","iopub.execute_input":"2023-09-23T09:27:23.221556Z","iopub.status.idle":"2023-09-23T09:27:23.229483Z","shell.execute_reply.started":"2023-09-23T09:27:23.221516Z","shell.execute_reply":"2023-09-23T09:27:23.228478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_hat=[1 if prediction>0.5 else 0 for prediction in y_hat]","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:23.232039Z","iopub.execute_input":"2023-09-23T09:27:23.232378Z","iopub.status.idle":"2023-09-23T09:27:23.239761Z","shell.execute_reply.started":"2023-09-23T09:27:23.232293Z","shell.execute_reply":"2023-09-23T09:27:23.238835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_mp3_16k_mono(filename):\n    res=tfio.audio.AudioIOTensor(filename)\n    tensor=res.to_tensor()\n    tensor=tf.math.reduce_sum(tensor,axis=1)/2\n    sample_rate=res.rate\n    sample_rate=tf.cast(sample_rate,dtype=tf.int64)\n    wav=tfio.audio.resample(tensor,rate_in=sample_rate,rate_out=16000)\n    return wav","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:23.240794Z","iopub.execute_input":"2023-09-23T09:27:23.241020Z","iopub.status.idle":"2023-09-23T09:27:23.254936Z","shell.execute_reply.started":"2023-09-23T09:27:23.240993Z","shell.execute_reply":"2023-09-23T09:27:23.254132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mp3=os.path.join('/kaggle/input','birdsong-recognition','example_test_audio', 'BLKFR-10-CPL_20190611_093000.pt540.mp3')\nwav=load_mp3_16k_mono(mp3)\naudio_slices=tf.keras.utils.timeseries_dataset_from_array(wav,wav,sequence_length=48000,sequence_stride=48000,batch_size=1)\nsamples,index=audio_slices.as_numpy_iterator().next()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:23.383041Z","iopub.execute_input":"2023-09-23T09:27:23.383454Z","iopub.status.idle":"2023-09-23T09:27:24.587895Z","shell.execute_reply.started":"2023-09-23T09:27:23.383416Z","shell.execute_reply":"2023-09-23T09:27:24.586969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def preprocess_mp3(sample,index):\n    sample=sample[0]\n    zero_padding=tf.zeros([48000]-tf.shape(sample),dtype=tf.float32)\n    wav=tf.concat([zero_padding,sample],0)\n    spectrogram=tf.signal.stft(wav,frame_length=320,frame_step=32)\n    spectrogram=tf.abs(spectrogram)\n    spectrogram=tf.expand_dims(spectrogram,axis=2)\n    return spectrogram","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:24.589689Z","iopub.execute_input":"2023-09-23T09:27:24.589984Z","iopub.status.idle":"2023-09-23T09:27:24.596310Z","shell.execute_reply.started":"2023-09-23T09:27:24.589945Z","shell.execute_reply":"2023-09-23T09:27:24.595539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"audio_slices = tf.keras.utils.timeseries_dataset_from_array(wav, wav, sequence_length=48000, sequence_stride=48000, batch_size=1)\naudio_slices = audio_slices.map(preprocess_mp3)\naudio_slices = audio_slices.batch(64)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:24.597628Z","iopub.execute_input":"2023-09-23T09:27:24.598069Z","iopub.status.idle":"2023-09-23T09:27:24.728355Z","shell.execute_reply.started":"2023-09-23T09:27:24.598031Z","shell.execute_reply":"2023-09-23T09:27:24.727578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yhat = model.predict(audio_slices)\n# yhat = [1 if prediction > 0.99 else 0 for prediction in yhat]","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:24.735786Z","iopub.execute_input":"2023-09-23T09:27:24.736385Z","iopub.status.idle":"2023-09-23T09:27:35.216101Z","shell.execute_reply.started":"2023-09-23T09:27:24.736353Z","shell.execute_reply":"2023-09-23T09:27:35.215260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_list = []\nfor x in yhat : \n    temp = list(x)\n    ind = temp.index(max(temp))\n    test_list.append([0 if i!=ind else 1 for i in range(5)])\nprint(test_list)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.218036Z","iopub.execute_input":"2023-09-23T09:27:35.218330Z","iopub.status.idle":"2023-09-23T09:27:35.227127Z","shell.execute_reply.started":"2023-09-23T09:27:35.218293Z","shell.execute_reply":"2023-09-23T09:27:35.224857Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test_list)","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.228990Z","iopub.execute_input":"2023-09-23T09:27:35.229255Z","iopub.status.idle":"2023-09-23T09:27:35.239317Z","shell.execute_reply.started":"2023-09-23T09:27:35.229220Z","shell.execute_reply":"2023-09-23T09:27:35.238437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat=[key for key,group in groupby(test_list)]\n# calls=tf.math.reduce_sum(y_hat).numpy()","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.240920Z","iopub.execute_input":"2023-09-23T09:27:35.241233Z","iopub.status.idle":"2023-09-23T09:27:35.250313Z","shell.execute_reply.started":"2023-09-23T09:27:35.241197Z","shell.execute_reply":"2023-09-23T09:27:35.249604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_hat\nprint(len(y_hat))","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.251682Z","iopub.execute_input":"2023-09-23T09:27:35.251972Z","iopub.status.idle":"2023-09-23T09:27:35.263327Z","shell.execute_reply.started":"2023-09-23T09:27:35.251937Z","shell.execute_reply":"2023-09-23T09:27:35.262444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dic = {}\nfor x in y_hat :\n    if tuple(x) in dic :\n        dic[tuple(x)] += 1\n    else:\n        dic[tuple(x)] = 1","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.264792Z","iopub.execute_input":"2023-09-23T09:27:35.265267Z","iopub.status.idle":"2023-09-23T09:27:35.272333Z","shell.execute_reply.started":"2023-09-23T09:27:35.265231Z","shell.execute_reply":"2023-09-23T09:27:35.271509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dic","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.276791Z","iopub.execute_input":"2023-09-23T09:27:35.277011Z","iopub.status.idle":"2023-09-23T09:27:35.285261Z","shell.execute_reply.started":"2023-09-23T09:27:35.276985Z","shell.execute_reply":"2023-09-23T09:27:35.284451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# results={}\n# for file in os.listdir(os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Forest Recordings')):\n#     FILEPATH=os.path.join('/kaggle/input','z-by-hp-unlocked-challenge-3-signal-processing','Forest Recordings',file)\n#     wav=load_mp3_16k_mono(FILEPATH)\n#     audio_slices=tf.keras.utils.timeseries_dataset_from_array(wav,wav,sequence_length=48000,sequence_stride=48000,batch_size=1)\n#     audio_slices=audio_slices.map(preprocess_mp3)\n#     audio_slices=audio_slices.batch(64)\n#     y_hat=model.predict(audio_slices)\n#     results[file]=y_hat","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.286591Z","iopub.execute_input":"2023-09-23T09:27:35.287405Z","iopub.status.idle":"2023-09-23T09:27:35.295441Z","shell.execute_reply.started":"2023-09-23T09:27:35.287369Z","shell.execute_reply":"2023-09-23T09:27:35.294623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results={}\nfor file in os.listdir(os.path.join('/kaggle/input','birdsong-recognition','example_test_audio')):\n    FILEPATH=os.path.join('/kaggle/input','birdsong-recognition','example_test_audio',file)\n    wav=load_mp3_16k_mono(FILEPATH)\n    audio_slices=tf.keras.utils.timeseries_dataset_from_array(wav,wav,sequence_length=48000,sequence_stride=48000,batch_size=1)\n    audio_slices=audio_slices.map(preprocess_mp3)\n    audio_slices=audio_slices.batch(64)\n    y_hat=model.predict(audio_slices)\n    results[file]=y_hat","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:35.296868Z","iopub.execute_input":"2023-09-23T09:27:35.297319Z","iopub.status.idle":"2023-09-23T09:27:47.620553Z","shell.execute_reply.started":"2023-09-23T09:27:35.297237Z","shell.execute_reply":"2023-09-23T09:27:47.619728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.624291Z","iopub.execute_input":"2023-09-23T09:27:47.624523Z","iopub.status.idle":"2023-09-23T09:27:47.655999Z","shell.execute_reply.started":"2023-09-23T09:27:47.624496Z","shell.execute_reply":"2023-09-23T09:27:47.655169Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# class_preds={}\n# for file,logits in results.items():\n#     class_preds[file]=[1 if prediction>0.99 else 0 for prediction in logits]\n# #class_preds","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2023-09-23T09:27:47.657335Z","iopub.execute_input":"2023-09-23T09:27:47.657671Z","iopub.status.idle":"2023-09-23T09:27:47.661453Z","shell.execute_reply.started":"2023-09-23T09:27:47.657627Z","shell.execute_reply":"2023-09-23T09:27:47.660776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_preds={}\nfor file,logits in results.items():\n    test_list1 = []\n    for x in logits : \n        temp = list(x)\n        ind = temp.index(max(temp))\n        test_list1.append([0 if i!=ind else 1 for i in range(5)])\n    class_preds[file]=test_list1\n#class_preds\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.663086Z","iopub.execute_input":"2023-09-23T09:27:47.663559Z","iopub.status.idle":"2023-09-23T09:27:47.675511Z","shell.execute_reply.started":"2023-09-23T09:27:47.663521Z","shell.execute_reply":"2023-09-23T09:27:47.674764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_preds","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.677006Z","iopub.execute_input":"2023-09-23T09:27:47.677348Z","iopub.status.idle":"2023-09-23T09:27:47.724143Z","shell.execute_reply.started":"2023-09-23T09:27:47.677313Z","shell.execute_reply":"2023-09-23T09:27:47.723445Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_name = {(1,0,0,0,0) : \"Pinjay\", (0,1,0,0,0) : \"Amecro\" , (0,0,1,0,0) : \"Crawre\" ,(0,0,0,1,0) : \"Fiespa\" ,(0,0,0,0,1) : \"Foxspa\"}","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.725528Z","iopub.execute_input":"2023-09-23T09:27:47.725804Z","iopub.status.idle":"2023-09-23T09:27:47.731336Z","shell.execute_reply.started":"2023-09-23T09:27:47.725767Z","shell.execute_reply":"2023-09-23T09:27:47.730606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"postprocessed={}\nfor file,scores in class_preds.items():\n    postprocessed[file]=tf.math.reduce_sum([key for key,group in groupby(scores)]).numpy()\n#postprocessed","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.732781Z","iopub.execute_input":"2023-09-23T09:27:47.733252Z","iopub.status.idle":"2023-09-23T09:27:47.744986Z","shell.execute_reply.started":"2023-09-23T09:27:47.733214Z","shell.execute_reply":"2023-09-23T09:27:47.744124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_pred={}\n\nfor file,scores in class_preds.items():\n    record = [key for key,group in groupby(scores)]\n    d = {}\n    for l in record :\n        \n        if bird_name[tuple(l)] in d :\n            d[bird_name[tuple(l)]] += 1\n        else:\n            d[bird_name[tuple(l)]] = 1 \n    bird_pred[file] = d","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.746223Z","iopub.execute_input":"2023-09-23T09:27:47.746631Z","iopub.status.idle":"2023-09-23T09:27:47.755637Z","shell.execute_reply.started":"2023-09-23T09:27:47.746594Z","shell.execute_reply":"2023-09-23T09:27:47.754856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird_pred","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.756984Z","iopub.execute_input":"2023-09-23T09:27:47.757461Z","iopub.status.idle":"2023-09-23T09:27:47.772531Z","shell.execute_reply.started":"2023-09-23T09:27:47.757377Z","shell.execute_reply":"2023-09-23T09:27:47.771815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import csv\nwith open('submission.csv','w',newline='')as f:\n    writer=csv.writer(f,delimiter=',')\n    writer.writerow(['clip_name','call_count'])\n    for key, value in bird_pred.items():\n        writer.writerow([key,value])","metadata":{"execution":{"iopub.status.busy":"2023-09-23T09:27:47.773948Z","iopub.execute_input":"2023-09-23T09:27:47.774358Z","iopub.status.idle":"2023-09-23T09:27:47.782421Z","shell.execute_reply.started":"2023-09-23T09:27:47.774319Z","shell.execute_reply":"2023-09-23T09:27:47.781698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}