{"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":"none","dataSources":[{"sourceId":7634,"databundleVersionId":46676,"sourceType":"competition"}],"dockerImageVersionId":30262,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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-06-10T01:27:48.824707Z","iopub.execute_input":"2024-06-10T01:27:48.825447Z","iopub.status.idle":"2024-06-10T01:27:48.834470Z","shell.execute_reply.started":"2024-06-10T01:27:48.825409Z","shell.execute_reply":"2024-06-10T01:27:48.833537Z"},"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-06-10T01:57:40.540033Z","iopub.execute_input":"2024-06-10T01:57:40.541027Z","iopub.status.idle":"2024-06-10T01:57:40.548116Z","shell.execute_reply.started":"2024-06-10T01:57:40.540986Z","shell.execute_reply":"2024-06-10T01:57:40.547010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install pyunpack \n!pip install patool","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:44:02.636900Z","iopub.execute_input":"2024-06-10T01:44:02.637690Z","iopub.status.idle":"2024-06-10T01:44:25.687435Z","shell.execute_reply.started":"2024-06-10T01:44:02.637656Z","shell.execute_reply":"2024-06-10T01:44:25.686192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs(\"./data\", exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:44:28.022356Z","iopub.execute_input":"2024-06-10T01:44:28.023236Z","iopub.status.idle":"2024-06-10T01:44:28.028767Z","shell.execute_reply.started":"2024-06-10T01:44:28.023177Z","shell.execute_reply":"2024-06-10T01:44:28.027694Z"},"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-06-10T01:28:14.496113Z","iopub.execute_input":"2024-06-10T01:28:14.496425Z","iopub.status.idle":"2024-06-10T01:29:41.330054Z","shell.execute_reply.started":"2024-06-10T01:28:14.496395Z","shell.execute_reply":"2024-06-10T01:29:41.328532Z"},"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-06-10T01:57:48.532542Z","iopub.execute_input":"2024-06-10T01:57:48.532924Z","iopub.status.idle":"2024-06-10T01:57:48.559664Z","shell.execute_reply.started":"2024-06-10T01:57:48.532891Z","shell.execute_reply":"2024-06-10T01:57:48.558246Z"},"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-06-10T01:57:58.096476Z","iopub.execute_input":"2024-06-10T01:57:58.096855Z","iopub.status.idle":"2024-06-10T01:57:58.145052Z","shell.execute_reply.started":"2024-06-10T01:57:58.096819Z","shell.execute_reply":"2024-06-10T01:57:58.143589Z"},"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-06-10T01:57:59.087208Z","iopub.execute_input":"2024-06-10T01:57:59.088386Z","iopub.status.idle":"2024-06-10T01:57:59.094242Z","shell.execute_reply.started":"2024-06-10T01:57:59.088336Z","shell.execute_reply":"2024-06-10T01:57:59.093111Z"},"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-06-10T01:58:00.121346Z","iopub.execute_input":"2024-06-10T01:58:00.122043Z","iopub.status.idle":"2024-06-10T01:58:00.129670Z","shell.execute_reply.started":"2024-06-10T01:58:00.122007Z","shell.execute_reply":"2024-06-10T01:58:00.128742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"create_silence()","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:45:38.127323Z","iopub.execute_input":"2024-06-10T01:45:38.127739Z","iopub.status.idle":"2024-06-10T01:45:40.071255Z","shell.execute_reply.started":"2024-06-10T01:45:38.127703Z","shell.execute_reply":"2024-06-10T01:45:40.070187Z"},"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-06-10T01:58:05.866033Z","iopub.execute_input":"2024-06-10T01:58:05.866967Z","iopub.status.idle":"2024-06-10T01:58:05.874017Z","shell.execute_reply.started":"2024-06-10T01:58:05.866924Z","shell.execute_reply":"2024-06-10T01:58:05.873037Z"},"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-10T01:58:07.804566Z","iopub.execute_input":"2024-06-10T01:58:07.804979Z","iopub.status.idle":"2024-06-10T01:58:07.818514Z","shell.execute_reply.started":"2024-06-10T01:58:07.804942Z","shell.execute_reply":"2024-06-10T01:58:07.817522Z"},"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-10T01:58:08.938162Z","iopub.execute_input":"2024-06-10T01:58:08.938596Z","iopub.status.idle":"2024-06-10T01:58:08.951805Z","shell.execute_reply.started":"2024-06-10T01:58:08.938557Z","shell.execute_reply":"2024-06-10T01:58:08.950820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#validation_list.extend(testing_list)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:58:10.030978Z","iopub.execute_input":"2024-06-10T01:58:10.031881Z","iopub.status.idle":"2024-06-10T01:58:10.035850Z","shell.execute_reply.started":"2024-06-10T01:58:10.031841Z","shell.execute_reply":"2024-06-10T01:58:10.034880Z"},"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-10T01:58:11.350939Z","iopub.execute_input":"2024-06-10T01:58:11.351703Z","iopub.status.idle":"2024-06-10T01:58:11.357323Z","shell.execute_reply.started":"2024-06-10T01:58:11.351662Z","shell.execute_reply":"2024-06-10T01:58:11.356247Z"},"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-10T01:58:17.399853Z","iopub.execute_input":"2024-06-10T01:58:17.400678Z","iopub.status.idle":"2024-06-10T01:58:25.056526Z","shell.execute_reply.started":"2024-06-10T01:58:17.400640Z","shell.execute_reply":"2024-06-10T01:58:25.055640Z"},"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-10T01:58:25.058645Z","iopub.execute_input":"2024-06-10T01:58:25.058993Z","iopub.status.idle":"2024-06-10T01:58:25.064137Z","shell.execute_reply.started":"2024-06-10T01:58:25.058965Z","shell.execute_reply":"2024-06-10T01:58:25.063084Z"},"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-10T01:58:25.065511Z","iopub.execute_input":"2024-06-10T01:58:25.065842Z","iopub.status.idle":"2024-06-10T01:58:25.077531Z","shell.execute_reply.started":"2024-06-10T01:58:25.065812Z","shell.execute_reply":"2024-06-10T01:58:25.076505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(class_counts)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:58:25.079599Z","iopub.execute_input":"2024-06-10T01:58:25.079959Z","iopub.status.idle":"2024-06-10T01:58:25.088296Z","shell.execute_reply.started":"2024-06-10T01:58:25.079928Z","shell.execute_reply":"2024-06-10T01:58:25.087356Z"},"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-10T01:58:25.670649Z","iopub.execute_input":"2024-06-10T01:58:25.671042Z","iopub.status.idle":"2024-06-10T01:58:25.901775Z","shell.execute_reply.started":"2024-06-10T01:58:25.671007Z","shell.execute_reply":"2024-06-10T01:58:25.900738Z"},"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-06-10T01:58:30.903846Z","iopub.execute_input":"2024-06-10T01:58:30.904558Z","iopub.status.idle":"2024-06-10T01:58:30.914346Z","shell.execute_reply.started":"2024-06-10T01:58:30.904519Z","shell.execute_reply":"2024-06-10T01:58:30.913109Z"},"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-10T01:58:31.249666Z","iopub.execute_input":"2024-06-10T01:58:31.250442Z","iopub.status.idle":"2024-06-10T01:58:31.545253Z","shell.execute_reply.started":"2024-06-10T01:58:31.250407Z","shell.execute_reply":"2024-06-10T01:58:31.544064Z"},"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-10T01:58:36.412236Z","iopub.execute_input":"2024-06-10T01:58:36.412661Z","iopub.status.idle":"2024-06-10T01:58:36.426628Z","shell.execute_reply.started":"2024-06-10T01:58:36.412625Z","shell.execute_reply":"2024-06-10T01:58:36.425189Z"},"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-10T01:58:39.632013Z","iopub.execute_input":"2024-06-10T01:58:39.632443Z","iopub.status.idle":"2024-06-10T01:58:39.640181Z","shell.execute_reply.started":"2024-06-10T01:58:39.632404Z","shell.execute_reply":"2024-06-10T01:58:39.639016Z"},"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.322700Z","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.590440Z","shell.execute_reply.started":"2024-06-10T01:54:11.205900Z","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.960670Z","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-06-10T01:59:58.583399Z","iopub.execute_input":"2024-06-10T01:59:58.583752Z","iopub.status.idle":"2024-06-10T01:59:59.028909Z","shell.execute_reply.started":"2024-06-10T01:59:58.583723Z","shell.execute_reply":"2024-06-10T01:59:59.027808Z"},"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-06-10T01:59:59.650909Z","iopub.execute_input":"2024-06-10T01:59:59.651827Z","iopub.status.idle":"2024-06-10T01:59:59.656008Z","shell.execute_reply.started":"2024-06-10T01:59:59.651788Z","shell.execute_reply":"2024-06-10T01:59:59.654971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir = \"./data/train/audio/\"\n\nX_train = np.load(\"./data/X_train.npy\")\ny_train = np.load(\"./data/y_train.npy\")\n\nX_val = np.load(\"./data/X_val.npy\")\ny_val = np.load(\"./data/y_val.npy\")","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:59:59.985854Z","iopub.execute_input":"2024-06-10T01:59:59.986250Z","iopub.status.idle":"2024-06-10T02:00:01.721901Z","shell.execute_reply.started":"2024-06-10T01:59:59.986217Z","shell.execute_reply":"2024-06-10T02:00:01.720754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:04.931242Z","iopub.execute_input":"2024-06-10T02:00:04.932129Z","iopub.status.idle":"2024-06-10T02:00:04.938305Z","shell.execute_reply.started":"2024-06-10T02:00:04.932092Z","shell.execute_reply":"2024-06-10T02:00:04.937230Z"},"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-06-10T02:00:06.284750Z","iopub.execute_input":"2024-06-10T02:00:06.285143Z","iopub.status.idle":"2024-06-10T02:00:06.290965Z","shell.execute_reply.started":"2024-06-10T02:00:06.285109Z","shell.execute_reply":"2024-06-10T02:00:06.289885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = os.listdir(train_dir)\nclasses","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:08.334656Z","iopub.execute_input":"2024-06-10T02:00:08.335819Z","iopub.status.idle":"2024-06-10T02:00:08.345870Z","shell.execute_reply.started":"2024-06-10T02:00:08.335759Z","shell.execute_reply":"2024-06-10T02:00:08.344125Z"},"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)\nclass_weights","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:08.740435Z","iopub.execute_input":"2024-06-10T02:00:08.741425Z","iopub.status.idle":"2024-06-10T02:00:08.766391Z","shell.execute_reply.started":"2024-06-10T02:00:08.741377Z","shell.execute_reply":"2024-06-10T02:00:08.765393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NB_CLASSES = len(classes)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:09.291211Z","iopub.execute_input":"2024-06-10T02:00:09.291603Z","iopub.status.idle":"2024-06-10T02:00:09.296717Z","shell.execute_reply.started":"2024-06-10T02:00:09.291569Z","shell.execute_reply":"2024-06-10T02:00:09.295747Z"},"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-06-10T02:00:10.115934Z","iopub.execute_input":"2024-06-10T02:00:10.116340Z","iopub.status.idle":"2024-06-10T02:00:10.125073Z","shell.execute_reply.started":"2024-06-10T02:00:10.116297Z","shell.execute_reply":"2024-06-10T02:00:10.124052Z"},"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-06-10T02:00:10.516787Z","iopub.execute_input":"2024-06-10T02:00:10.517710Z","iopub.status.idle":"2024-06-10T02:00:10.812599Z","shell.execute_reply.started":"2024-06-10T02:00:10.517672Z","shell.execute_reply":"2024-06-10T02:00:10.811772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:11.042635Z","iopub.execute_input":"2024-06-10T02:00:11.043546Z","iopub.status.idle":"2024-06-10T02:00:11.051321Z","shell.execute_reply.started":"2024-06-10T02:00:11.043506Z","shell.execute_reply":"2024-06-10T02:00:11.049637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install livelossplot","metadata":{"execution":{"iopub.status.busy":"2024-06-10T02:00:11.563921Z","iopub.execute_input":"2024-06-10T02:00:11.564868Z","iopub.status.idle":"2024-06-10T02:00:23.316917Z","shell.execute_reply.started":"2024-06-10T02:00:11.564820Z","shell.execute_reply":"2024-06-10T02:00:23.315706Z"},"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-06-10T02:01:12.999646Z","iopub.execute_input":"2024-06-10T02:01:13.000041Z","iopub.status.idle":"2024-06-10T02:01:13.007563Z","shell.execute_reply.started":"2024-06-10T02:01:13.000007Z","shell.execute_reply":"2024-06-10T02:01:13.006266Z"},"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-06-10T02:01:15.597589Z","iopub.execute_input":"2024-06-10T02:01:15.598002Z","iopub.status.idle":"2024-06-10T02:01:15.606098Z","shell.execute_reply.started":"2024-06-10T02:01:15.597966Z","shell.execute_reply":"2024-06-10T02:01:15.604995Z"},"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=10, 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 % 3 == 2:\n                x = self._shortcut_layer(input_res, x)\n                input_res = x\n                \n        # Bidirectional LSTM layers\n        bilstm = Bidirectional(LSTM(units=128, return_sequences=True))(x)\n        bilstm = Dropout(0.25)(bilstm)\n        bilstm = BatchNormalization()(bilstm)\n\n        bilstm = Bidirectional(LSTM(units=128, 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-06-10T02:01:16.313420Z","iopub.execute_input":"2024-06-10T02:01:16.313782Z","iopub.status.idle":"2024-06-10T02:01:16.344548Z","shell.execute_reply.started":"2024-06-10T02:01:16.313750Z","shell.execute_reply":"2024-06-10T02:01:16.343425Z"},"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-06-10T02:01:17.488817Z","iopub.execute_input":"2024-06-10T02:01:17.489218Z","iopub.status.idle":"2024-06-10T02:01:17.494662Z","shell.execute_reply.started":"2024-06-10T02:01:17.489164Z","shell.execute_reply":"2024-06-10T02:01:17.493379Z"},"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-06-10T02:01:18.103344Z","iopub.execute_input":"2024-06-10T02:01:18.103749Z","iopub.status.idle":"2024-06-10T02:01:19.716633Z","shell.execute_reply.started":"2024-06-10T02:01:18.103716Z","shell.execute_reply":"2024-06-10T02:01:19.715590Z"},"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 = '4-10-2022'\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-06-10T02:01:56.929149Z","iopub.execute_input":"2024-06-10T02:01:56.929911Z","iopub.status.idle":"2024-06-10T02:01:59.275833Z","shell.execute_reply.started":"2024-06-10T02:01:56.929875Z","shell.execute_reply":"2024-06-10T02:01:59.274626Z"},"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-06-10T02:01:59.278069Z","iopub.execute_input":"2024-06-10T02:01:59.278635Z","iopub.status.idle":"2024-06-10T02:57:46.771059Z","shell.execute_reply.started":"2024-06-10T02:01:59.278597Z","shell.execute_reply":"2024-06-10T02:57:46.769998Z"},"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":{"execution":{"iopub.status.busy":"2024-06-10T03:11:40.859233Z","iopub.execute_input":"2024-06-10T03:11:40.859684Z","iopub.status.idle":"2024-06-10T03:11:41.535618Z","shell.execute_reply.started":"2024-06-10T03:11:40.859649Z","shell.execute_reply":"2024-06-10T03:11:41.534630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inception.model.load_weights(\"./best_weights.h5\")","metadata":{"execution":{"iopub.status.busy":"2024-06-10T03:11:43.271027Z","iopub.execute_input":"2024-06-10T03:11:43.271944Z","iopub.status.idle":"2024-06-10T03:11:43.394974Z","shell.execute_reply.started":"2024-06-10T03:11:43.271905Z","shell.execute_reply":"2024-06-10T03:11:43.393935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inception.model.evaluate(X_val, y_val)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T03:11:44.601169Z","iopub.execute_input":"2024-06-10T03:11:44.602099Z","iopub.status.idle":"2024-06-10T03:11:51.083134Z","shell.execute_reply.started":"2024-06-10T03:11:44.602059Z","shell.execute_reply":"2024-06-10T03:11:51.082229Z"},"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-06-10T03:33:28.605536Z","iopub.execute_input":"2024-06-10T03:33:28.606596Z","iopub.status.idle":"2024-06-10T03:33:36.355985Z","shell.execute_reply.started":"2024-06-10T03:33:28.606554Z","shell.execute_reply":"2024-06-10T03:33:36.355069Z"},"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-06-10T03:33:36.357978Z","iopub.execute_input":"2024-06-10T03:33:36.358334Z","iopub.status.idle":"2024-06-10T03:33:36.376100Z","shell.execute_reply.started":"2024-06-10T03:33:36.358303Z","shell.execute_reply":"2024-06-10T03:33:36.375243Z"},"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-06-10T03:33:36.377144Z","iopub.execute_input":"2024-06-10T03:33:36.377475Z","iopub.status.idle":"2024-06-10T03:33:37.053726Z","shell.execute_reply.started":"2024-06-10T03:33:36.377447Z","shell.execute_reply":"2024-06-10T03:33:37.052734Z"},"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-06-10T03:33:37.055667Z","iopub.execute_input":"2024-06-10T03:33:37.055984Z","iopub.status.idle":"2024-06-10T03:33:37.225176Z","shell.execute_reply.started":"2024-06-10T03:33:37.055953Z","shell.execute_reply":"2024-06-10T03:33:37.224384Z"},"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-06-10T03:33:37.226325Z","iopub.execute_input":"2024-06-10T03:33:37.226621Z","iopub.status.idle":"2024-06-10T03:33:41.383732Z","shell.execute_reply.started":"2024-06-10T03:33:37.226593Z","shell.execute_reply":"2024-06-10T03:33:41.382691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%reset -f","metadata":{"execution":{"iopub.status.busy":"2024-06-10T01:38:19.540007Z","iopub.status.idle":"2024-06-10T01:38:19.540393Z","shell.execute_reply.started":"2024-06-10T01:38:19.540177Z","shell.execute_reply":"2024-06-10T01:38:19.540217Z"},"trusted":true},"execution_count":null,"outputs":[]}]}