{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":7634,"databundleVersionId":46676,"sourceType":"competition"},{"sourceId":8771518,"sourceType":"datasetVersion","datasetId":5271253}],"dockerImageVersionId":30262,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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)\n\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\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\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":"2024-07-01T14:15:14.754794Z","iopub.execute_input":"2024-07-01T14:15:14.755470Z","iopub.status.idle":"2024-07-01T14:15:14.789221Z","shell.execute_reply.started":"2024-07-01T14:15:14.755386Z","shell.execute_reply":"2024-07-01T14:15:14.788316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import csv\nimport librosa\nimport librosa.display\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:20:25.301307Z","iopub.execute_input":"2024-07-01T14:20:25.301716Z","iopub.status.idle":"2024-07-01T14:20:25.308600Z","shell.execute_reply.started":"2024-07-01T14:20:25.301685Z","shell.execute_reply":"2024-07-01T14:20:25.307460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pyunpack \n!pip install patool","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:15:16.921300Z","iopub.execute_input":"2024-07-01T14:15:16.921708Z","iopub.status.idle":"2024-07-01T14:15:40.814734Z","shell.execute_reply.started":"2024-07-01T14:15:16.921668Z","shell.execute_reply":"2024-07-01T14:15:40.813702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs(\"./data\", exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:15:40.817514Z","iopub.execute_input":"2024-07-01T14:15:40.817844Z","iopub.status.idle":"2024-07-01T14:15:40.823660Z","shell.execute_reply.started":"2024-07-01T14:15:40.817810Z","shell.execute_reply":"2024-07-01T14:15:40.822630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pyunpack import Archive\n\nArchive(\"../input/tensorflow-speech-recognition-challenge/train.7z\").extractall(\"./data\")\n#Archive(\"../input/tensorflow-speech-recognition-challenge/test.7z\").extractall(\"./\")","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:15:40.824822Z","iopub.execute_input":"2024-07-01T14:15:40.825128Z","iopub.status.idle":"2024-07-01T14:17:06.632850Z","shell.execute_reply.started":"2024-07-01T14:15:40.825100Z","shell.execute_reply":"2024-07-01T14:17:06.631652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir = \"./data/train/audio/\"\n\nclasses = os.listdir(train_dir)\nclasses.remove(\"_background_noise_\")\nclasses","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:06.634519Z","iopub.execute_input":"2024-07-01T14:17:06.634854Z","iopub.status.idle":"2024-07-01T14:17:06.645958Z","shell.execute_reply.started":"2024-07-01T14:17:06.634820Z","shell.execute_reply":"2024-07-01T14:17:06.645099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%bash\nmv ./data/train/audio/_background_noise_ ./data/train\nls ./data/train/audio","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:06.646974Z","iopub.execute_input":"2024-07-01T14:17:06.647271Z","iopub.status.idle":"2024-07-01T14:17:06.682067Z","shell.execute_reply.started":"2024-07-01T14:17:06.647244Z","shell.execute_reply":"2024-07-01T14:17:06.681056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def split_arr(arr):\n    \"\"\"\n    split an array into chunks of length 16000\n    Returns:\n        list of arrays\n    \"\"\"\n    return np.split(arr, np.arange(16000, len(arr), 16000))\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:06.683930Z","iopub.execute_input":"2024-07-01T14:17:06.684315Z","iopub.status.idle":"2024-07-01T14:17:06.690427Z","shell.execute_reply.started":"2024-07-01T14:17:06.684273Z","shell.execute_reply":"2024-07-01T14:17:06.689329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import soundfile as sf\n\ndef create_silence():\n    \"\"\"\n    reads wav files in background noises folder, \n    splits them and saves to silence folder in train_dir\n    \"\"\"\n    for file in os.listdir(\"./data/train/_background_noise_/\"):\n        if \".wav\" in file:\n            sig, sr = librosa.load(\"./data/train/_background_noise_/\"+file, sr = 16000) \n            sig_arr = split_arr(sig)\n            if not os.path.exists(train_dir+\"silence/\"):\n                os.makedirs(train_dir+\"silence/\")\n            for ind, arr in enumerate(sig_arr):\n                file_name = \"frag%d\" %ind + \"_%s\" %file # example: frag0_running_tap.wav\n                sf.write(train_dir+\"silence/\"+file_name, arr, 16000)\n  ","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:06.691647Z","iopub.execute_input":"2024-07-01T14:17:06.691926Z","iopub.status.idle":"2024-07-01T14:17:06.700534Z","shell.execute_reply.started":"2024-07-01T14:17:06.691899Z","shell.execute_reply":"2024-07-01T14:17:06.699545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"create_silence()","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:06.704275Z","iopub.execute_input":"2024-07-01T14:17:06.704603Z","iopub.status.idle":"2024-07-01T14:17:09.021061Z","shell.execute_reply.started":"2024-07-01T14:17:06.704567Z","shell.execute_reply":"2024-07-01T14:17:09.019722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"folders = os.listdir(train_dir)\n# put folders in same order as in the classes list, used when making sets\nall_classes = [x for x in classes]\nfor ind, cl in enumerate(folders):\n    if cl not in classes:\n        all_classes.append(cl)\nprint(all_classes)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:09.022893Z","iopub.execute_input":"2024-07-01T14:17:09.023765Z","iopub.status.idle":"2024-07-01T14:17:09.031089Z","shell.execute_reply.started":"2024-07-01T14:17:09.023717Z","shell.execute_reply":"2024-07-01T14:17:09.030035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open(\"./data/train/validation_list.txt\") as val_list:\n    validation_list = [row[0] for row in csv.reader(val_list)]\nassert len(validation_list) == 6798, \"Validation files not loaded\"\n    ","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:10.184358Z","iopub.execute_input":"2024-06-24T08:04:10.185085Z","iopub.status.idle":"2024-06-24T08:04:10.200788Z","shell.execute_reply.started":"2024-06-24T08:04:10.185044Z","shell.execute_reply":"2024-06-24T08:04:10.199858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open(\"./data/train/testing_list.txt\") as val_list:\n    validation_list = [row[0] for row in csv.reader(val_list)]\nassert len(validation_list) == 6835, \"testing files not loaded\"\n    ","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:10.202263Z","iopub.execute_input":"2024-06-24T08:04:10.203308Z","iopub.status.idle":"2024-06-24T08:04:10.218789Z","shell.execute_reply.started":"2024-06-24T08:04:10.203245Z","shell.execute_reply":"2024-06-24T08:04:10.217907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#validation_list.extend(testing_list)","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:10.219997Z","iopub.execute_input":"2024-06-24T08:04:10.220362Z","iopub.status.idle":"2024-06-24T08:04:10.228121Z","shell.execute_reply.started":"2024-06-24T08:04:10.220325Z","shell.execute_reply":"2024-06-24T08:04:10.227179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# add silence files to validation_list\nfor i, file in enumerate(os.listdir(train_dir+\"silence/\")):\n    if i%10 == 0:\n        validation_list.append(\"silence/\"+file)","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:10.233007Z","iopub.execute_input":"2024-06-24T08:04:10.233387Z","iopub.status.idle":"2024-06-24T08:04:10.239665Z","shell.execute_reply.started":"2024-06-24T08:04:10.233359Z","shell.execute_reply":"2024-06-24T08:04:10.238581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_list  = []\nall_files_list = []\nclass_counts = {}\n\nfor folder in folders:\n    files = os.listdir(train_dir+folder)\n    for i, f in enumerate(files):\n        all_files_list.append(folder+\"/\"+f)\n        path = folder+'/'+f\n        if path not in validation_list:\n            training_list .append(folder+'/'+f)\n        class_counts[folder] = i\n\n#remove filenames from validation_list that don't exist anymore (due to eda)\nvalidation_list = list(set(validation_list).intersection(all_files_list))","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:10.240903Z","iopub.execute_input":"2024-06-24T08:04:10.241307Z","iopub.status.idle":"2024-06-24T08:04:17.883437Z","shell.execute_reply.started":"2024-06-24T08:04:10.241259Z","shell.execute_reply":"2024-06-24T08:04:17.882555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"assert len(validation_list) + len(training_list) == len(all_files_list), \"Not All files splitted\"","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:17.884609Z","iopub.execute_input":"2024-06-24T08:04:17.884888Z","iopub.status.idle":"2024-06-24T08:04:17.889844Z","shell.execute_reply.started":"2024-06-24T08:04:17.884863Z","shell.execute_reply":"2024-06-24T08:04:17.888861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# check random file name\nprint(training_list[345], \"Size training set: \", len(training_list), 'size validation set: ', len(validation_list))","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:17.890965Z","iopub.execute_input":"2024-06-24T08:04:17.891293Z","iopub.status.idle":"2024-06-24T08:04:17.899936Z","shell.execute_reply.started":"2024-06-24T08:04:17.891261Z","shell.execute_reply":"2024-06-24T08:04:17.898992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(class_counts)","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:17.901105Z","iopub.execute_input":"2024-06-24T08:04:17.901428Z","iopub.status.idle":"2024-06-24T08:04:17.911125Z","shell.execute_reply.started":"2024-06-24T08:04:17.901395Z","shell.execute_reply":"2024-06-24T08:04:17.910028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x, r = librosa.load(train_dir+\"yes/bfdb9801_nohash_0.wav\", sr=16000)\n\nprint(\"Min: \", np.min(x), \n      \"\\nMax: \", np.max(x),\n      \"\\nMean: \", np.mean(x),\n      \"\\nMedian: \", np.median(x),\n      \"\\nVariance: \", np.var(x),\n      \"\\nLength: \", len(x),)\nplt.plot(x)","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:17.912679Z","iopub.execute_input":"2024-06-24T08:04:17.912983Z","iopub.status.idle":"2024-06-24T08:04:18.187789Z","shell.execute_reply.started":"2024-06-24T08:04:17.912957Z","shell.execute_reply":"2024-06-24T08:04:18.186742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Turn all wav files into spectrograms\n","metadata":{}},{"cell_type":"code","source":"def make_spec(file, file_dir=train_dir, flip=False, ps=False, st = 4):\n    \"\"\"\n    create a melspectrogram from the amplitude of the sound\n    \n    Args:\n        file (str): filename\n        file_dir (str): directory path\n        flip (bool): reverse time axis\n        ps (bool): pitch shift\n        st (int): half-note steps for pitch shift\n    Returns:\n        np.array with shape (122,85) (time, freq)\n    \"\"\"\n    \n    sig, sr = librosa.load(file_dir+file, sr=16000)\n    \n    if len(sig) < 16000: #pad shorter than 1 sec audio with ramp to zero\n        sig = np.pad(sig, (0,16000-len(sig)), \"linear_ramp\")\n        \n    if ps:\n        sig = librosa.effects.pitch_shift(sig, rate, st)\n        \n    D = librosa.amplitude_to_db(librosa.stft(sig[:16000], \n                                             n_fft=512, \n                                             hop_length=128,\n                                             center=False),\n                               ref=np.max)\n    S = librosa.feature.melspectrogram(S=D, n_mels=85).T\n    \n    if flip:\n        S = np.flipud(S)\n    \n    return S.astype(np.float32)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:09.032234Z","iopub.execute_input":"2024-07-01T14:17:09.032543Z","iopub.status.idle":"2024-07-01T14:17:09.043281Z","shell.execute_reply.started":"2024-07-01T14:17:09.032515Z","shell.execute_reply":"2024-07-01T14:17:09.042306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"librosa.display.specshow(make_spec(\"yes/bfdb9801_nohash_0.wav\"),\n                         x_axis=\"mel\",\n                         fmax=8000,\n                         y_axis=\"time\",\n                         sr=16000,\n                         hop_length=128)","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:18.202484Z","iopub.execute_input":"2024-06-24T08:04:18.202806Z","iopub.status.idle":"2024-06-24T08:04:18.562274Z","shell.execute_reply.started":"2024-06-24T08:04:18.202776Z","shell.execute_reply":"2024-06-24T08:04:18.560296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"make_spec('yes/bfdb9801_nohash_0.wav').shape","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:18.565249Z","iopub.execute_input":"2024-06-24T08:04:18.565873Z","iopub.status.idle":"2024-06-24T08:04:18.585619Z","shell.execute_reply.started":"2024-06-24T08:04:18.565815Z","shell.execute_reply":"2024-06-24T08:04:18.584177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_sets(file_list=training_list):\n    X_array = np.zeros([len(file_list), 122, 85])\n    y_array = np.zeros([len(file_list)])\n    for ind, file in enumerate(file_list):\n        if ind%2000 == 0:\n            print(ind, file)\n        try:\n            X_array[ind] = make_spec(file)\n        except ValueError:\n            print(ind, file, ValueError)\n        y_array[ind] = all_classes.index(file.rsplit('/')[0])\n        \n    return X_array, y_array","metadata":{"execution":{"iopub.status.busy":"2024-06-24T08:04:18.590671Z","iopub.execute_input":"2024-06-24T08:04:18.591274Z","iopub.status.idle":"2024-06-24T08:04:18.609713Z","shell.execute_reply.started":"2024-06-24T08:04:18.591212Z","shell.execute_reply":"2024-06-24T08:04:18.607919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, y_train = create_sets() # takes a while","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:46:17.508485Z","iopub.execute_input":"2024-06-10T01:46:17.509354Z","iopub.status.idle":"2024-06-10T01:53:43.661355Z","shell.execute_reply.started":"2024-06-10T01:46:17.509315Z","shell.execute_reply":"2024-06-10T01:53:43.659812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:53:52.3227Z","iopub.execute_input":"2024-06-10T01:53:52.323733Z","iopub.status.idle":"2024-06-10T01:53:52.329514Z","shell.execute_reply.started":"2024-06-10T01:53:52.323692Z","shell.execute_reply":"2024-06-10T01:53:52.328589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:53:56.978287Z","iopub.execute_input":"2024-06-10T01:53:56.978658Z","iopub.status.idle":"2024-06-10T01:53:56.985432Z","shell.execute_reply.started":"2024-06-10T01:53:56.978629Z","shell.execute_reply":"2024-06-10T01:53:56.984383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"librosa.display.specshow(X_train[6500],\n                         x_axis=\"time\",\n                         fmax=8000,\n                         y_axis=\"mel\",\n                         sr=16000,\n                         hop_length=128)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:53:59.371438Z","iopub.execute_input":"2024-06-10T01:53:59.371835Z","iopub.status.idle":"2024-06-10T01:53:59.600168Z","shell.execute_reply.started":"2024-06-10T01:53:59.371802Z","shell.execute_reply":"2024-06-10T01:53:59.598755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('min: ',np.min(X_train), \n      '\\nmax: ', np.max(X_train), \n      '\\nmean: ', np.mean(X_train),\n      '\\nmedian: ', np.median(X_train),\n      '\\nvariance: ', np.var(X_train))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:54:00.847886Z","iopub.execute_input":"2024-06-10T01:54:00.848282Z","iopub.status.idle":"2024-06-10T01:54:11.204078Z","shell.execute_reply.started":"2024-06-10T01:54:00.848248Z","shell.execute_reply":"2024-06-10T01:54:11.203068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(X_train.flatten(), bins=50)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:54:11.205619Z","iopub.execute_input":"2024-06-10T01:54:11.205928Z","iopub.status.idle":"2024-06-10T01:54:24.59044Z","shell.execute_reply.started":"2024-06-10T01:54:11.2059Z","shell.execute_reply":"2024-06-10T01:54:24.589447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.save(\"./data/X_train.npy\", np.expand_dims(X_train, -1)+1.3)\nnp.save(\"./data/y_train.npy\", y_train.astype(np.int))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:54:24.592098Z","iopub.execute_input":"2024-06-10T01:54:24.592403Z","iopub.status.idle":"2024-06-10T01:54:46.988115Z","shell.execute_reply.started":"2024-06-10T01:54:24.592376Z","shell.execute_reply":"2024-06-10T01:54:46.986692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_val, y_val = create_sets(file_list=validation_list)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:58:49.960295Z","iopub.execute_input":"2024-06-10T01:58:49.960704Z","iopub.status.idle":"2024-06-10T01:59:40.018211Z","shell.execute_reply.started":"2024-06-10T01:58:49.96067Z","shell.execute_reply":"2024-06-10T01:59:40.016713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.save(\"./data/X_val.npy\", np.expand_dims(X_val, -1)+1.3)\nnp.save(\"./data/y_val.npy\", y_val.astype(np.int))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:59:47.827634Z","iopub.execute_input":"2024-06-10T01:59:47.828149Z","iopub.status.idle":"2024-06-10T01:59:48.542767Z","shell.execute_reply.started":"2024-06-10T01:59:47.828101Z","shell.execute_reply":"2024-06-10T01:59:48.541751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%reset -f","metadata":{"execution":{"iopub.status.busy":"2024-07-01T14:17:09.044551Z","iopub.execute_input":"2024-07-01T14:17:09.044894Z","iopub.status.idle":"2024-07-01T14:17:09.317591Z","shell.execute_reply.started":"2024-07-01T14:17:09.044864Z","shell.execute_reply":"2024-07-01T14:17:09.316609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport os","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:24:36.001880Z","iopub.execute_input":"2024-07-01T17:24:36.002273Z","iopub.status.idle":"2024-07-01T17:24:36.007039Z","shell.execute_reply.started":"2024-07-01T17:24:36.002237Z","shell.execute_reply":"2024-07-01T17:24:36.006040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir = \"./data/train/audio/\"\n\nX_train = np.load(\"/kaggle/input/speech-commands-feature-extract/X_train.npy\")\ny_train = np.load(\"/kaggle/input/speech-commands-feature-extract/y_train.npy\")\n\nX_val = np.load(\"/kaggle/input/speech-commands-feature-extract/X_val.npy\")\ny_val = np.load(\"/kaggle/input/speech-commands-feature-extract/y_val.npy\")","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:24:38.682525Z","iopub.execute_input":"2024-07-01T17:24:38.682934Z","iopub.status.idle":"2024-07-01T17:25:19.204961Z","shell.execute_reply.started":"2024-07-01T17:24:38.682897Z","shell.execute_reply":"2024-07-01T17:25:19.203799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.207207Z","iopub.execute_input":"2024-07-01T17:25:19.208075Z","iopub.status.idle":"2024-07-01T17:25:19.214246Z","shell.execute_reply.started":"2024-07-01T17:25:19.208028Z","shell.execute_reply":"2024-07-01T17:25:19.213378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.reshape((-1, X_train.shape[1], X_train.shape[2]))\nX_val = X_val.reshape((-1, X_val.shape[1], X_val.shape[2]))","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.215613Z","iopub.execute_input":"2024-07-01T17:25:19.215901Z","iopub.status.idle":"2024-07-01T17:25:19.225235Z","shell.execute_reply.started":"2024-07-01T17:25:19.215874Z","shell.execute_reply":"2024-07-01T17:25:19.224264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = os.listdir(train_dir)\nclasses","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.227747Z","iopub.execute_input":"2024-07-01T17:25:19.228032Z","iopub.status.idle":"2024-07-01T17:25:19.239084Z","shell.execute_reply.started":"2024-07-01T17:25:19.228004Z","shell.execute_reply":"2024-07-01T17:25:19.237984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from collections import Counter\n\ndef get_class_weights(y):\n    counter = Counter(y)\n    majority = max(counter.values())\n    return {cls: float(majority/count) for cls, count in counter.items()}\n\nclass_weights = get_class_weights(y_train)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.240264Z","iopub.execute_input":"2024-07-01T17:25:19.240582Z","iopub.status.idle":"2024-07-01T17:25:19.275422Z","shell.execute_reply.started":"2024-07-01T17:25:19.240541Z","shell.execute_reply":"2024-07-01T17:25:19.274571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NB_CLASSES = len(classes)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.276411Z","iopub.execute_input":"2024-07-01T17:25:19.276675Z","iopub.status.idle":"2024-07-01T17:25:19.286265Z","shell.execute_reply.started":"2024-07-01T17:25:19.276649Z","shell.execute_reply":"2024-07-01T17:25:19.285384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_list_dict(lst):\n    res_dct = {i: val for i, val in enumerate(lst)}\n    return res_dct\n         \nclasses_index = convert_list_dict(classes)\nclasses_index","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.287276Z","iopub.execute_input":"2024-07-01T17:25:19.287593Z","iopub.status.idle":"2024-07-01T17:25:19.300577Z","shell.execute_reply.started":"2024-07-01T17:25:19.287560Z","shell.execute_reply":"2024-07-01T17:25:19.299641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import to_categorical\n\ny_train = to_categorical(y_train, num_classes=NB_CLASSES)\ny_val = to_categorical(y_val, num_classes=NB_CLASSES)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.303576Z","iopub.execute_input":"2024-07-01T17:25:19.303888Z","iopub.status.idle":"2024-07-01T17:25:19.315937Z","shell.execute_reply.started":"2024-07-01T17:25:19.303860Z","shell.execute_reply":"2024-07-01T17:25:19.315088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.317171Z","iopub.execute_input":"2024-07-01T17:25:19.317472Z","iopub.status.idle":"2024-07-01T17:25:19.326692Z","shell.execute_reply.started":"2024-07-01T17:25:19.317444Z","shell.execute_reply":"2024-07-01T17:25:19.325656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install livelossplot","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:19.330310Z","iopub.execute_input":"2024-07-01T17:25:19.330650Z","iopub.status.idle":"2024-07-01T17:25:30.831682Z","shell.execute_reply.started":"2024-07-01T17:25:19.330623Z","shell.execute_reply":"2024-07-01T17:25:30.830408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import Conv1D, MaxPool1D, Concatenate, BatchNormalization, Activation, Input, Add, \\\n                         GlobalAveragePooling1D, Dense, Bidirectional, LSTM, Dropout\nfrom keras.models import Model\nfrom tensorflow.keras.optimizers import Adam\nfrom keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping\nfrom livelossplot import PlotLossesKeras\nfrom tensorflow.keras.metrics import Recall, Precision\nimport keras\nimport time","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:30.833718Z","iopub.execute_input":"2024-07-01T17:25:30.834584Z","iopub.status.idle":"2024-07-01T17:25:30.841787Z","shell.execute_reply.started":"2024-07-01T17:25:30.834535Z","shell.execute_reply":"2024-07-01T17:25:30.840601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras.backend as K\n\ndef f1_score(y_true, y_pred):\n    true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))\n    possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))\n    predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))\n    precision = true_positives / (predicted_positives + K.epsilon())\n    recall = true_positives / (possible_positives + K.epsilon())\n    f1_val = 2*(precision*recall)/(precision+recall+K.epsilon())\n    return f1_val","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:30.843036Z","iopub.execute_input":"2024-07-01T17:25:30.843303Z","iopub.status.idle":"2024-07-01T17:25:30.855225Z","shell.execute_reply.started":"2024-07-01T17:25:30.843276Z","shell.execute_reply":"2024-07-01T17:25:30.854198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Classifier_INCEPTION:\n    def __init__(self, weights_directory, input_shape, nb_classes, verbose=False, build=True, batch_size=64,\n                 nb_filters=32, use_residual=True, use_bottleneck=True, depth=8, kernel_size=41, nb_epochs=100):\n        self.weights_directory = weights_directory\n        self.nb_filters = nb_filters\n        self.use_residual = use_residual\n        self.use_bottleneck = use_bottleneck\n        self.depth = depth\n        self.kernel_size = kernel_size - 1\n        self.callbacks = None\n        self.batch_size = batch_size\n        self.bottleneck_size = 32\n        self.nb_epochs = nb_epochs\n\n        if build == True:\n            self.model = self.build_model(input_shape, nb_classes)\n            if (verbose == True):\n                self.model.summary()\n            self.verbose = verbose\n\n    def _inception_module(self, input_tensor, stride=1, activation='linear'):\n\n        if self.use_bottleneck and int(input_tensor.shape[-1]) > 1:\n            input_inception = Conv1D(filters=self.bottleneck_size, kernel_size=1,\n                                     padding='same', activation=activation, use_bias=False)(input_tensor)\n        else:\n            input_inception = input_tensor\n\n        kernel_size_s = [self.kernel_size // (2 ** i) for i in range(3)]\n\n        conv_list = []\n\n        for i in range(len(kernel_size_s)):\n            conv_list.append(Conv1D(filters=self.nb_filters, kernel_size=kernel_size_s[i],\n                                    strides=stride, padding='same', activation=activation, use_bias=False)(\n                input_inception))\n\n        max_pool_1 = MaxPool1D(pool_size=3, strides=stride, padding='same')(input_tensor)\n\n        conv_6 = Conv1D(filters=self.nb_filters, kernel_size=1,\n                        padding='same', activation=activation, use_bias=False)(max_pool_1)\n\n        conv_list.append(conv_6)\n\n        x = Concatenate(axis=2)(conv_list)\n        x = BatchNormalization()(x)\n        x = Activation(activation='relu')(x)\n        return x\n\n    def _shortcut_layer(self, input_tensor, out_tensor):\n        shortcut_y = Conv1D(filters=int(out_tensor.shape[-1]), kernel_size=1,\n                            padding='same', use_bias=False)(input_tensor)\n        shortcut_y = BatchNormalization()(shortcut_y)\n\n        x = Add()([shortcut_y, out_tensor])\n        x = Activation('relu')(x)\n        return x\n\n    def build_model(self, input_shape, nb_classes):\n        input_layer = Input(input_shape)\n\n        x = input_layer\n        input_res = input_layer\n\n        for d in range(self.depth):\n\n            x = self._inception_module(x)\n\n            if self.use_residual and d % 2 == 1:\n                x = self._shortcut_layer(input_res, x)\n                input_res = x\n                \n        # Bidirectional LSTM layers\n        bilstm = Bidirectional(LSTM(units=64, return_sequences=True))(x)\n        bilstm = Dropout(0.25)(bilstm)\n        bilstm = BatchNormalization()(bilstm)\n        \n        bilstm = Bidirectional(LSTM(units=64, return_sequences=True))(bilstm)\n        bilstm = Dropout(0.25)(bilstm)\n        bilstm = BatchNormalization()(bilstm)\n\n        gap_layer = GlobalAveragePooling1D()(bilstm)\n        \n\n        output_layer = Dense(nb_classes, activation='softmax')(gap_layer)\n\n        model = Model(inputs=input_layer, outputs=output_layer)\n\n        model.compile(loss='categorical_crossentropy', \n                      optimizer=Adam(),\n                      metrics=['accuracy', Precision(), Recall(), f1_score])\n\n        reduce_lr = ReduceLROnPlateau(monitor='val_accuracy', \n                                      factor=0.5, \n                                      patience=int(self.nb_epochs/20),\n                                      min_lr=0.0001)\n        \n        file_path = os.path.join(self.weights_directory,\"best_weights.h5\")\n        model_checkpoint = ModelCheckpoint(filepath=file_path, \n                                           monitor='val_accuracy',\n                                           mode=\"max\",\n                                           save_best_only=True)\n        \n        early_stopping = EarlyStopping(monitor=\"val_accuracy\", \n                                       mode=\"max\", \n                                       verbose=1, \n                                       patience=int(self.nb_epochs/10))\n        plotlosses = PlotLossesKeras()\n        self.callbacks = [reduce_lr, model_checkpoint, early_stopping, plotlosses]\n        return model\n\n    def fit(self, x_train, y_train, x_val, y_val, class_weights=None):       \n        if self.batch_size is None:\n            mini_batch_size = int(min(x_train.shape[0] / 10, 16))\n        else:\n            mini_batch_size = self.batch_size\n\n        start_time = time.time()\n        hist = self.model.fit(x_train, y_train, \n                              batch_size=mini_batch_size, \n                              epochs=self.nb_epochs,\n                              verbose=self.verbose, \n                              validation_data=(x_val, y_val), \n                              callbacks=self.callbacks)\n        \n        duration = time.time() - start_time\n        keras.backend.clear_session()\n        print(\"Model take {} S to train \".format(duration))\n        return hist","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:30.856780Z","iopub.execute_input":"2024-07-01T17:25:30.857074Z","iopub.status.idle":"2024-07-01T17:25:30.890180Z","shell.execute_reply.started":"2024-07-01T17:25:30.857036Z","shell.execute_reply":"2024-07-01T17:25:30.889220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"INPUT_SHAPE = X_train.shape[1:]\nBATCH_SIZE = 64","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:30.891292Z","iopub.execute_input":"2024-07-01T17:25:30.891639Z","iopub.status.idle":"2024-07-01T17:25:30.905285Z","shell.execute_reply.started":"2024-07-01T17:25:30.891610Z","shell.execute_reply":"2024-07-01T17:25:30.904372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WEIGHTS_DIR = \"./\"\ninception = Classifier_INCEPTION(WEIGHTS_DIR, INPUT_SHAPE, NB_CLASSES, 1, batch_size=BATCH_SIZE, build=True)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:30.906526Z","iopub.execute_input":"2024-07-01T17:25:30.906809Z","iopub.status.idle":"2024-07-01T17:25:32.463871Z","shell.execute_reply.started":"2024-07-01T17:25:30.906782Z","shell.execute_reply":"2024-07-01T17:25:32.462823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import plot_model\n\n#adjust these strings for organizeing the saved files\ndate = '1-7-2024'\n\nmodel_name = 'InceptionTime'\n\n# to save a png of the model you need pydot and graphviz installed\nplot_model(inception.model, \n           to_file = './{}_{}.png'.format(model_name,date), \n           show_shapes = True)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T16:42:09.877306Z","iopub.execute_input":"2024-07-01T16:42:09.878251Z","iopub.status.idle":"2024-07-01T16:42:12.055373Z","shell.execute_reply.started":"2024-07-01T16:42:09.878210Z","shell.execute_reply":"2024-07-01T16:42:12.053988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = inception.fit(X_train, y_train, X_val, y_val)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T16:42:22.190011Z","iopub.execute_input":"2024-07-01T16:42:22.190995Z","iopub.status.idle":"2024-07-01T16:58:07.110214Z","shell.execute_reply.started":"2024-07-01T16:42:22.190947Z","shell.execute_reply":"2024-07-01T16:58:07.109068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n%matplotlib inline\n\n#%% visualize training\nprint(history.history.keys())\n# summarize history for accuracy\nplt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.savefig('{}_{}_accuracy.png'.format(model_name, date),bbox_inches='tight')\nplt.show()\n# summarize history for loss\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('model loss')\nplt.ylabel('loss')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.savefig('{}_{}_loss.png'.format(model_name, date), bbox_inches='tight')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inception.model.load_weights(\"./best_weights.h5\")","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:32.465274Z","iopub.execute_input":"2024-07-01T17:25:32.465679Z","iopub.status.idle":"2024-07-01T17:25:32.581465Z","shell.execute_reply.started":"2024-07-01T17:25:32.465638Z","shell.execute_reply":"2024-07-01T17:25:32.580642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inception.model.evaluate(X_val, y_val)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:44.795454Z","iopub.execute_input":"2024-07-01T17:25:44.795863Z","iopub.status.idle":"2024-07-01T17:25:52.890491Z","shell.execute_reply.started":"2024-07-01T17:25:44.795828Z","shell.execute_reply":"2024-07-01T17:25:52.889493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat = inception.model.predict(X_val, batch_size = BATCH_SIZE, verbose = 1)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:25:52.892689Z","iopub.execute_input":"2024-07-01T17:25:52.893558Z","iopub.status.idle":"2024-07-01T17:25:57.496976Z","shell.execute_reply.started":"2024-07-01T17:25:52.893514Z","shell.execute_reply":"2024-07-01T17:25:57.495964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_curve, auc\nfrom itertools import cycle\n\ndef ROC_plot(y_true_ohe, y_hat_ohe, label_encoder, n_classes):    \n    lw = 2\n    fpr = dict()\n    tpr = dict()\n    roc_auc = dict()\n    for i in range(n_classes):\n        fpr[i], tpr[i], _ = roc_curve(y_true_ohe[:, i], y_hat_ohe[:, i])\n        roc_auc[i] = auc(fpr[i], tpr[i])\n                                  \n    all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)]))\n\n    mean_tpr = np.zeros_like(all_fpr)\n    for i in range(n_classes):\n        mean_tpr += np.interp(all_fpr, fpr[i], tpr[i])\n\n    mean_tpr /= n_classes\n    fpr[\"macro\"] = all_fpr\n    tpr[\"macro\"] = mean_tpr\n    roc_auc[\"macro\"] = auc(fpr[\"macro\"], tpr[\"macro\"])\n\n    fpr[\"micro\"], tpr[\"micro\"], _ = roc_curve(y_true_ohe.ravel(), y_hat_ohe.ravel())\n    roc_auc[\"micro\"] = auc(fpr[\"micro\"], tpr[\"micro\"])\n    \n    plt.figure(figsize=(20,20))\n    plt.plot(\n        fpr[\"micro\"],\n        tpr[\"micro\"],\n        label=\"micro-average ROC curve (area = {0:0.2f})\".format(roc_auc[\"micro\"]),\n        color=\"deeppink\",\n        linestyle=\":\",\n        linewidth=4,\n    )\n\n    plt.plot(\n        fpr[\"macro\"],\n        tpr[\"macro\"],\n        label=\"macro-average ROC curve (area = {0:0.2f})\".format(roc_auc[\"macro\"]),\n        color=\"navy\",\n        linestyle=\":\",\n        linewidth=4,\n    )\n\n    colors = cycle([\"aqua\", \"darkorange\", \"cornflowerblue\"])\n    for i, color in zip(range(n_classes), colors):\n        plt.plot(\n            fpr[i],\n            tpr[i],\n            color=color,\n            lw=lw,\n            label=\"ROC curve of class {0} (area = {1:0.2f})\".format(list(label_encoder.keys())[i], roc_auc[i]))\n\n    plt.plot([0, 1], [0, 1], \"k--\", lw=lw)\n    plt.xlim([0.0, 1.0])\n    plt.ylim([0.0, 1.05])\n    plt.xlabel(\"False Positive Rate\")\n    plt.ylabel(\"True Positive Rate\")\n    plt.title(\"multiclass characteristic\")\n    plt.legend(loc=\"lower right\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:26:26.629849Z","iopub.execute_input":"2024-07-01T17:26:26.630922Z","iopub.status.idle":"2024-07-01T17:26:26.649368Z","shell.execute_reply.started":"2024-07-01T17:26:26.630869Z","shell.execute_reply":"2024-07-01T17:26:26.648310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROC_plot(y_val, y_hat, classes_index, NB_CLASSES)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:26:26.834913Z","iopub.execute_input":"2024-07-01T17:26:26.835835Z","iopub.status.idle":"2024-07-01T17:26:27.536116Z","shell.execute_reply.started":"2024-07-01T17:26:26.835793Z","shell.execute_reply":"2024-07-01T17:26:27.535093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, precision_recall_fscore_support,confusion_matrix, classification_report, precision_score, recall_score\nfrom sklearn.metrics import f1_score as f1_score_rep\nimport seaborn as sn\nimport pandas as pd\n\n\ndef print_score(y_pred, y_real, label_encoder):\n    print(\"Accuracy: \", accuracy_score(y_real, y_pred))\n    print(\"Precision:: \", precision_score(y_real, y_pred, average=\"micro\"))\n    print(\"Recall:: \", recall_score(y_real, y_pred, average=\"micro\"))\n    print(\"F1_Score:: \", f1_score_rep(y_real, y_pred, average=\"micro\"))\n\n    print()\n    print(\"Macro precision_recall_fscore_support (macro) average\")\n    print(precision_recall_fscore_support(y_real, y_pred, average=\"macro\"))\n\n    print()\n    print(\"Macro precision_recall_fscore_support (micro) average\")\n    print(precision_recall_fscore_support(y_real, y_pred, average=\"micro\"))\n\n    print()\n    print(\"Macro precision_recall_fscore_support (weighted) average\")\n    print(precision_recall_fscore_support(y_real, y_pred, average=\"weighted\"))\n    \n    print()\n    print(\"Confusion Matrix\")\n    cm = confusion_matrix(y_real, y_pred)\n    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n    df_cm = pd.DataFrame(cm, index = [i for i in label_encoder],\n                  columns = [i for i in label_encoder])\n    plt.figure(figsize = (20,20))\n    sn.heatmap(df_cm, annot=True)\n\n    print()\n    print(\"Classification Report\")\n    print(classification_report(y_real, y_pred, target_names=label_encoder))","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:26:28.903551Z","iopub.execute_input":"2024-07-01T17:26:28.903948Z","iopub.status.idle":"2024-07-01T17:26:28.916943Z","shell.execute_reply.started":"2024-07-01T17:26:28.903912Z","shell.execute_reply":"2024-07-01T17:26:28.915718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_hat = np.argmax(y_hat, axis=1)\ny_true = np.argmax(y_val, axis=1)\n\nprint_score(y_hat, y_true, classes)","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:26:29.509446Z","iopub.execute_input":"2024-07-01T17:26:29.510151Z","iopub.status.idle":"2024-07-01T17:26:34.665444Z","shell.execute_reply.started":"2024-07-01T17:26:29.510111Z","shell.execute_reply":"2024-07-01T17:26:34.664264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%reset -f","metadata":{"execution":{"iopub.status.busy":"2024-07-01T17:24:03.553744Z","iopub.execute_input":"2024-07-01T17:24:03.554111Z","iopub.status.idle":"2024-07-01T17:24:04.151263Z","shell.execute_reply.started":"2024-07-01T17:24:03.554079Z","shell.execute_reply":"2024-07-01T17:24:04.150193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}