{"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!pip uninstall tensorflow-cloud -y\n!pip install tensorflow_datasets==4.0.1\n\nimport re\nimport os\nimport numpy as np\nimport pandas as pd\nimport tensorflow as tf\n#from tensorflow import keras\nimport tensorflow_datasets as tfds\nimport tensorflow_addons as tfa\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.utils import class_weight\nimport datetime\n\nimport scipy\nimport gc\n\n#try:\n#    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()\n#    print('Device:', tpu.master())\n#    tf.config.experimental_connect_to_cluster(tpu)\n#    tf.tpu.experimental.initialize_tpu_system(tpu)\n#    strategy = tf.distribute.experimental.TPUStrategy(tpu)\n#except:\n#    strategy = tf.distribute.get_strategy()\n#print('Number of replicas:', strategy.num_replicas_in_sync)\n    \nprint(tf.__version__)\nprint(tfds.__version__)\n\n\n\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\n#import os\n#for 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":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":22.951377,"end_time":"2020-12-28T01:14:01.134036","exception":false,"start_time":"2020-12-28T01:13:38.182659","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:06:38.302921Z","iopub.execute_input":"2022-01-29T09:06:38.303292Z","iopub.status.idle":"2022-01-29T09:06:58.780293Z","shell.execute_reply.started":"2022-01-29T09:06:38.303177Z","shell.execute_reply":"2022-01-29T09:06:58.779516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load And Split","metadata":{"papermill":{"duration":0.049464,"end_time":"2020-12-28T01:14:01.234228","exception":false,"start_time":"2020-12-28T01:14:01.184764","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Custom variables\nmanual_dir = r'/kaggle/input/retinopathy-btgraham300/tensorflow_datasets'\n\n#AUTOTUNE = tf.data.experimental.AUTOTUNE\n#BATCH_SIZE = 16 * strategy.num_replicas_in_sync\n#IMAGE_SIZE = [300, 300]\n#EPOCHS = 25","metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","papermill":{"duration":0.056914,"end_time":"2020-12-28T01:14:01.338503","exception":false,"start_time":"2020-12-28T01:14:01.281589","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:06:58.781925Z","iopub.execute_input":"2022-01-29T09:06:58.782174Z","iopub.status.idle":"2022-01-29T09:06:58.788564Z","shell.execute_reply.started":"2022-01-29T09:06:58.782139Z","shell.execute_reply":"2022-01-29T09:06:58.787267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Configure dataset\n(ds_train, ds_val, ds_test), ds_info = \\\ntfds.load('diabetic_retinopathy_detection/btgraham-300:3.0.0',\n          split=['train', 'validation', 'test'],\n          download=False,data_dir=manual_dir, with_info=True,\n          shuffle_files=False, as_supervised=False)","metadata":{"papermill":{"duration":3.25107,"end_time":"2020-12-28T01:14:04.675984","exception":false,"start_time":"2020-12-28T01:14:01.424914","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:06:58.791181Z","iopub.execute_input":"2022-01-29T09:06:58.791382Z","iopub.status.idle":"2022-01-29T09:07:01.217833Z","shell.execute_reply.started":"2022-01-29T09:06:58.791352Z","shell.execute_reply":"2022-01-29T09:07:01.215875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(ds_info)","metadata":{"papermill":{"duration":0.062091,"end_time":"2020-12-28T01:14:04.78836","exception":false,"start_time":"2020-12-28T01:14:04.726269","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.220097Z","iopub.execute_input":"2022-01-29T09:07:01.220474Z","iopub.status.idle":"2022-01-29T09:07:01.226469Z","shell.execute_reply.started":"2022-01-29T09:07:01.220429Z","shell.execute_reply":"2022-01-29T09:07:01.224922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#datagen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)","metadata":{"papermill":{"duration":0.055488,"end_time":"2020-12-28T01:14:04.894003","exception":false,"start_time":"2020-12-28T01:14:04.838515","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.227648Z","iopub.execute_input":"2022-01-29T09:07:01.228331Z","iopub.status.idle":"2022-01-29T09:07:01.237274Z","shell.execute_reply.started":"2022-01-29T09:07:01.228287Z","shell.execute_reply":"2022-01-29T09:07:01.235438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from tensorflow.keras.utils import Sequence\n#from imblearn.over_sampling import RandomOverSampler\n#from imblearn.keras import balanced_batch_generator\n\n#class BalancedDataGenerator(Sequence):\n#    \"\"\"ImageDataGenerator + RandomOversampling\"\"\"\n#    def __init__(self, x, y, datagen, batch_size=32):\n#        self.datagen = datagen\n#        self.batch_size = min(batch_size, x.shape[0])\n#        datagen.fit(x)\n#        self.gen, self.steps_per_epoch = balanced_batch_generator(x.reshape(x.shape[0], -1), y, sampler=RandomOverSampler(), batch_size=self.batch_size, keep_sparse=True)\n#        self._shape = (self.steps_per_epoch * batch_size, *x.shape[1:])\n        \n#    def __len__(self):\n#        return self.steps_per_epoch\n\n#    def __getitem__(self, idx):\n#        x_batch, y_batch = self.gen.__next__()\n#        x_batch = x_batch.reshape(-1, *self._shape[1:])\n#        return self.datagen.flow(x_batch, y_batch, batch_size=self.batch_size).next()","metadata":{"papermill":{"duration":0.056539,"end_time":"2020-12-28T01:14:05.003588","exception":false,"start_time":"2020-12-28T01:14:04.947049","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.238740Z","iopub.execute_input":"2022-01-29T09:07:01.239655Z","iopub.status.idle":"2022-01-29T09:07:01.245016Z","shell.execute_reply.started":"2022-01-29T09:07:01.239606Z","shell.execute_reply":"2022-01-29T09:07:01.244156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#def map_image(tensor):\n#    return tensor['label']","metadata":{"papermill":{"duration":0.056794,"end_time":"2020-12-28T01:14:05.110856","exception":false,"start_time":"2020-12-28T01:14:05.054062","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.246466Z","iopub.execute_input":"2022-01-29T09:07:01.247316Z","iopub.status.idle":"2022-01-29T09:07:01.253633Z","shell.execute_reply.started":"2022-01-29T09:07:01.247273Z","shell.execute_reply":"2022-01-29T09:07:01.252779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#[i for i in ds_train.map(map_image)]","metadata":{"papermill":{"duration":0.057973,"end_time":"2020-12-28T01:14:05.220198","exception":false,"start_time":"2020-12-28T01:14:05.162225","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.255303Z","iopub.execute_input":"2022-01-29T09:07:01.255640Z","iopub.status.idle":"2022-01-29T09:07:01.262027Z","shell.execute_reply.started":"2022-01-29T09:07:01.255601Z","shell.execute_reply":"2022-01-29T09:07:01.261179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#balanced_gen = BalancedDataGenerator(\n#    [img for img in ds_train.map(lambda tensor:tensor['image'])],\n#    [label for label in ds_train.map(lambda tensor:tensor['label'])], \n#    datagen, batch_size=32)","metadata":{"papermill":{"duration":0.058086,"end_time":"2020-12-28T01:14:05.328535","exception":false,"start_time":"2020-12-28T01:14:05.270449","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.263836Z","iopub.execute_input":"2022-01-29T09:07:01.264589Z","iopub.status.idle":"2022-01-29T09:07:01.270217Z","shell.execute_reply.started":"2022-01-29T09:07:01.264542Z","shell.execute_reply":"2022-01-29T09:07:01.269418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#for i in ds_train.take(1):\n#    print(i)\n#    print(\"Espacio\")\n#    print(i['image'].numpy())","metadata":{"papermill":{"duration":0.059947,"end_time":"2020-12-28T01:14:05.439154","exception":false,"start_time":"2020-12-28T01:14:05.379207","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.274750Z","iopub.execute_input":"2022-01-29T09:07:01.274969Z","iopub.status.idle":"2022-01-29T09:07:01.278968Z","shell.execute_reply.started":"2022-01-29T09:07:01.274942Z","shell.execute_reply":"2022-01-29T09:07:01.278145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{"papermill":{"duration":0.050455,"end_time":"2020-12-28T01:14:05.541292","exception":false,"start_time":"2020-12-28T01:14:05.490837","status":"completed"},"tags":[]}},{"cell_type":"code","source":"vis = tfds.visualization.show_examples(ds_train, ds_info)","metadata":{"papermill":{"duration":1.336358,"end_time":"2020-12-28T01:14:06.927623","exception":false,"start_time":"2020-12-28T01:14:05.591265","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:01.280852Z","iopub.execute_input":"2022-01-29T09:07:01.281588Z","iopub.status.idle":"2022-01-29T09:07:02.395302Z","shell.execute_reply.started":"2022-01-29T09:07:01.281546Z","shell.execute_reply":"2022-01-29T09:07:02.394640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for tensor in ds_train.take(1):\n    image=tensor['image'].numpy()\n    label=tensor['label'].numpy()","metadata":{"papermill":{"duration":0.186386,"end_time":"2020-12-28T01:14:07.173083","exception":false,"start_time":"2020-12-28T01:14:06.986697","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:02.396284Z","iopub.execute_input":"2022-01-29T09:07:02.397325Z","iopub.status.idle":"2022-01-29T09:07:02.499431Z","shell.execute_reply.started":"2022-01-29T09:07:02.397285Z","shell.execute_reply":"2022-01-29T09:07:02.498627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Etiqueta: \",label)\nplt.imshow(image);","metadata":{"papermill":{"duration":0.283335,"end_time":"2020-12-28T01:14:07.516637","exception":false,"start_time":"2020-12-28T01:14:07.233302","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:02.500949Z","iopub.execute_input":"2022-01-29T09:07:02.501211Z","iopub.status.idle":"2022-01-29T09:07:02.749784Z","shell.execute_reply.started":"2022-01-29T09:07:02.501159Z","shell.execute_reply":"2022-01-29T09:07:02.749066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_list = [tensor['label'] for tensor in ds_train.as_numpy_iterator()]\nunique, counts = np.unique(label_list, return_counts=True)\nplt.bar(unique, counts)\nprint(*zip(unique, counts))","metadata":{"papermill":{"duration":56.593414,"end_time":"2020-12-28T01:15:04.174517","exception":false,"start_time":"2020-12-28T01:14:07.581103","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:02.751324Z","iopub.execute_input":"2022-01-29T09:07:02.751844Z","iopub.status.idle":"2022-01-29T09:07:50.188950Z","shell.execute_reply.started":"2022-01-29T09:07:02.751797Z","shell.execute_reply":"2022-01-29T09:07:50.188130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Class weights","metadata":{"papermill":{"duration":0.061403,"end_time":"2020-12-28T01:15:04.301853","exception":false,"start_time":"2020-12-28T01:15:04.24045","status":"completed"},"tags":[]}},{"cell_type":"code","source":"from sklearn.utils.class_weight import compute_class_weight, compute_sample_weight\n \nclass_weights = compute_class_weight('balanced', np.unique(label_list), label_list)\nsample_weights = compute_sample_weight('balanced', label_list)\n \nclass_weights_dict = dict(enumerate(class_weights))","metadata":{"papermill":{"duration":0.15425,"end_time":"2020-12-28T01:15:04.519799","exception":false,"start_time":"2020-12-28T01:15:04.365549","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.190661Z","iopub.execute_input":"2022-01-29T09:07:50.191208Z","iopub.status.idle":"2022-01-29T09:07:50.288710Z","shell.execute_reply.started":"2022-01-29T09:07:50.191147Z","shell.execute_reply":"2022-01-29T09:07:50.276811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sample_weights)","metadata":{"papermill":{"duration":0.074199,"end_time":"2020-12-28T01:15:04.659705","exception":false,"start_time":"2020-12-28T01:15:04.585506","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.296813Z","iopub.execute_input":"2022-01-29T09:07:50.298464Z","iopub.status.idle":"2022-01-29T09:07:50.310817Z","shell.execute_reply.started":"2022-01-29T09:07:50.298297Z","shell.execute_reply":"2022-01-29T09:07:50.309699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = np.bincount(label_list)\nii = np.nonzero(y)[0]\nlist_zip =[*zip(ii,y[ii])]\nlist_zip","metadata":{"papermill":{"duration":0.081781,"end_time":"2020-12-28T01:15:04.807273","exception":false,"start_time":"2020-12-28T01:15:04.725492","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.313601Z","iopub.execute_input":"2022-01-29T09:07:50.315614Z","iopub.status.idle":"2022-01-29T09:07:50.338036Z","shell.execute_reply.started":"2022-01-29T09:07:50.315571Z","shell.execute_reply":"2022-01-29T09:07:50.336890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"papermill":{"duration":0.075313,"end_time":"2020-12-28T01:15:04.955288","exception":false,"start_time":"2020-12-28T01:15:04.879975","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.339802Z","iopub.execute_input":"2022-01-29T09:07:50.340271Z","iopub.status.idle":"2022-01-29T09:07:50.348544Z","shell.execute_reply.started":"2022-01-29T09:07:50.340232Z","shell.execute_reply":"2022-01-29T09:07:50.346945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"[y[i]*class_weights[i] for i in range(4)]\n    ","metadata":{"papermill":{"duration":0.07732,"end_time":"2020-12-28T01:15:05.098945","exception":false,"start_time":"2020-12-28T01:15:05.021625","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.350675Z","iopub.execute_input":"2022-01-29T09:07:50.351666Z","iopub.status.idle":"2022-01-29T09:07:50.364601Z","shell.execute_reply.started":"2022-01-29T09:07:50.351612Z","shell.execute_reply":"2022-01-29T09:07:50.363419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Reject undersampling","metadata":{"papermill":{"duration":0.067888,"end_time":"2020-12-28T01:15:05.232929","exception":false,"start_time":"2020-12-28T01:15:05.165041","status":"completed"},"tags":[]}},{"cell_type":"code","source":"#def count(counts, tensor):\n#  labels = tensor['label']\n\n#  class_1 = labels == 1\n#  class_1 = tf.cast(class_1, tf.int32)\n\n#  class_0 = labels == 0\n#  class_0 = tf.cast(class_0, tf.int32)\n\n#  class_2 = labels == 2\n#  class_2 = tf.cast(class_2, tf.int32)\n    \n#  class_3 = labels == 3\n#  class_3 = tf.cast(class_3, tf.int32)\n    \n#  class_4 = labels == 4\n#  class_4 = tf.cast(class_4, tf.int32)\n\n#  counts['class_0'] += tf.reduce_sum(class_0)\n#  counts['class_1'] += tf.reduce_sum(class_1)\n#  counts['class_2'] += tf.reduce_sum(class_2)\n#  counts['class_3'] += tf.reduce_sum(class_3)\n#  counts['class_4'] += tf.reduce_sum(class_4)  \n\n#  return counts","metadata":{"papermill":{"duration":0.073709,"end_time":"2020-12-28T01:15:05.372214","exception":false,"start_time":"2020-12-28T01:15:05.298505","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.365879Z","iopub.execute_input":"2022-01-29T09:07:50.369368Z","iopub.status.idle":"2022-01-29T09:07:50.374635Z","shell.execute_reply.started":"2022-01-29T09:07:50.369324Z","shell.execute_reply":"2022-01-29T09:07:50.373794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#counts = ds_train.take(35126).reduce(\n#    initial_state={'class_0': 0, 'class_1': 0, 'class_2': 0, 'class_3': 0, 'class_4': 0},\n#    reduce_func = count)\n#\n#counts = np.array([counts['class_0'].numpy(),\n#                   counts['class_1'].numpy(),\n#                   counts['class_2'].numpy(),\n#                   counts['class_3'].numpy(),\n#                   counts['class_4'].numpy()]).astype(np.float32)\n\n#fractions = counts/counts.sum()\n#print(*fractions)","metadata":{"papermill":{"duration":0.076871,"end_time":"2020-12-28T01:15:05.517347","exception":false,"start_time":"2020-12-28T01:15:05.440476","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.377077Z","iopub.execute_input":"2022-01-29T09:07:50.378489Z","iopub.status.idle":"2022-01-29T09:07:50.387155Z","shell.execute_reply.started":"2022-01-29T09:07:50.378448Z","shell.execute_reply":"2022-01-29T09:07:50.386429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#def class_func(tensor): #Aux func for resampling 'cause the data is imbalance\n#    return tensor['label']","metadata":{"papermill":{"duration":0.074042,"end_time":"2020-12-28T01:15:05.65774","exception":false,"start_time":"2020-12-28T01:15:05.583698","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.388659Z","iopub.execute_input":"2022-01-29T09:07:50.389622Z","iopub.status.idle":"2022-01-29T09:07:50.394881Z","shell.execute_reply.started":"2022-01-29T09:07:50.389581Z","shell.execute_reply":"2022-01-29T09:07:50.394112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#resampler = tf.data.experimental.rejection_resample(\n#    class_func, target_dist=[0.2,0.2,0.2,0.2,0.2], initial_dist=fractions)","metadata":{"papermill":{"duration":0.07394,"end_time":"2020-12-28T01:15:05.797664","exception":false,"start_time":"2020-12-28T01:15:05.723724","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.396221Z","iopub.execute_input":"2022-01-29T09:07:50.397000Z","iopub.status.idle":"2022-01-29T09:07:50.402479Z","shell.execute_reply.started":"2022-01-29T09:07:50.396957Z","shell.execute_reply":"2022-01-29T09:07:50.401711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#resample_ds = ds_train.apply(resampler).take(3800)","metadata":{"papermill":{"duration":0.073232,"end_time":"2020-12-28T01:15:05.939227","exception":false,"start_time":"2020-12-28T01:15:05.865995","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.403839Z","iopub.execute_input":"2022-01-29T09:07:50.404916Z","iopub.status.idle":"2022-01-29T09:07:50.410024Z","shell.execute_reply.started":"2022-01-29T09:07:50.404875Z","shell.execute_reply":"2022-01-29T09:07:50.409273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#balanced_ds = resample_ds.map(lambda extra_label, features_and_label: features_and_label)","metadata":{"papermill":{"duration":0.075273,"end_time":"2020-12-28T01:15:06.084136","exception":false,"start_time":"2020-12-28T01:15:06.008863","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.411345Z","iopub.execute_input":"2022-01-29T09:07:50.413289Z","iopub.status.idle":"2022-01-29T09:07:50.419572Z","shell.execute_reply.started":"2022-01-29T09:07:50.413247Z","shell.execute_reply":"2022-01-29T09:07:50.418853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#label_list_balanced = [tensor['label'].numpy() for tensor in balanced_ds.take(3800)]\n#unique, counts = np.unique(label_list_balanced, return_counts=True)\n#plt.bar(unique, counts)\n#print(*zip(unique, counts))","metadata":{"papermill":{"duration":0.076212,"end_time":"2020-12-28T01:15:06.227594","exception":false,"start_time":"2020-12-28T01:15:06.151382","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.421105Z","iopub.execute_input":"2022-01-29T09:07:50.422018Z","iopub.status.idle":"2022-01-29T09:07:50.431661Z","shell.execute_reply.started":"2022-01-29T09:07:50.421977Z","shell.execute_reply":"2022-01-29T09:07:50.430360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preprocesing","metadata":{"papermill":{"duration":0.069094,"end_time":"2020-12-28T01:15:06.36454","exception":false,"start_time":"2020-12-28T01:15:06.295446","status":"completed"},"tags":[]}},{"cell_type":"code","source":"def transform_images(row, size, reescale=True):\n    x_train = tf.image.resize(row['image'], (size, size))\n    if reescale:\n        x_train = x_train  / 255\n    return x_train, tf.one_hot(row['label'], depth=5)\ndef transform_images_complete(row, size):\n    x_train = tf.image.resize(row['image'], (size, size))\n    x_train = x_train  / 255\n    return x_train, tf.one_hot(row['label'], depth=5), row['name']\n\nds_train = ds_train.map(lambda row:transform_images(row, 400))\n#ds_train = resample_ds.map(lambda _, row:transform_images(row, 400))\nds_val = ds_val.map(lambda row:transform_images(row, 400))\n#ds_test_all = ds_test.map(lambda row:transform_images_complete(row, 300))\nds_test = ds_test.map(lambda row:transform_images(row, 400, reescale=True))","metadata":{"papermill":{"duration":0.250461,"end_time":"2020-12-28T01:15:06.685962","exception":false,"start_time":"2020-12-28T01:15:06.435501","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.433067Z","iopub.execute_input":"2022-01-29T09:07:50.434048Z","iopub.status.idle":"2022-01-29T09:07:50.667543Z","shell.execute_reply.started":"2022-01-29T09:07:50.434005Z","shell.execute_reply":"2022-01-29T09:07:50.666717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Num classes: \" + str(ds_info.features['label'].num_classes))\nprint(\"Class names: \" + str(ds_info.features['label'].names))","metadata":{"papermill":{"duration":0.078548,"end_time":"2020-12-28T01:15:06.833241","exception":false,"start_time":"2020-12-28T01:15:06.754693","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.673024Z","iopub.execute_input":"2022-01-29T09:07:50.673876Z","iopub.status.idle":"2022-01-29T09:07:50.680561Z","shell.execute_reply.started":"2022-01-29T09:07:50.673810Z","shell.execute_reply":"2022-01-29T09:07:50.679698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NUM_TRAIN_IMAGES = tf.data.experimental.cardinality(ds_train).numpy()\nprint(\"Num training images: \" + str(NUM_TRAIN_IMAGES))\n\nNUM_VAL_IMAGES = tf.data.experimental.cardinality(ds_val).numpy()\nprint(\"Num validating images: \" + str(NUM_VAL_IMAGES))\n\nNUM_TEST_IMAGES = tf.data.experimental.cardinality(ds_test).numpy()\nprint(\"Num testing images: \" + str(NUM_TEST_IMAGES))","metadata":{"papermill":{"duration":0.081631,"end_time":"2020-12-28T01:15:06.984948","exception":false,"start_time":"2020-12-28T01:15:06.903317","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.682015Z","iopub.execute_input":"2022-01-29T09:07:50.682993Z","iopub.status.idle":"2022-01-29T09:07:50.691749Z","shell.execute_reply.started":"2022-01-29T09:07:50.682954Z","shell.execute_reply":"2022-01-29T09:07:50.690954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#ds_train = ds_train.cache()\nds_train = ds_train.shuffle(1000)\nds_train = ds_train.batch(32)\n#ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)\n\n#ds_val = ds_val.cache()\nds_val = ds_val.shuffle(1000)\nds_val = ds_val.batch(32)\n#ds_val = ds_val.prefetch(tf.data.experimental.AUTOTUNE)\n\n#ds_test = ds_test.cache()\nds_test = ds_test.batch(32)\n#ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)","metadata":{"papermill":{"duration":0.083427,"end_time":"2020-12-28T01:15:07.138932","exception":false,"start_time":"2020-12-28T01:15:07.055505","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.693183Z","iopub.execute_input":"2022-01-29T09:07:50.694142Z","iopub.status.idle":"2022-01-29T09:07:50.705810Z","shell.execute_reply.started":"2022-01-29T09:07:50.694107Z","shell.execute_reply":"2022-01-29T09:07:50.705023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in ds_train.take(1):\n    print(i)","metadata":{"papermill":{"duration":4.096326,"end_time":"2020-12-28T01:15:11.307459","exception":false,"start_time":"2020-12-28T01:15:07.211133","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:50.707333Z","iopub.execute_input":"2022-01-29T09:07:50.708105Z","iopub.status.idle":"2022-01-29T09:07:54.085629Z","shell.execute_reply.started":"2022-01-29T09:07:50.708068Z","shell.execute_reply":"2022-01-29T09:07:54.084812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Build Model","metadata":{"papermill":{"duration":0.0738,"end_time":"2020-12-28T01:15:11.483615","exception":false,"start_time":"2020-12-28T01:15:11.409815","status":"completed"},"tags":[]}},{"cell_type":"code","source":"\n\nfrom tensorflow.keras.layers import Input # Input Layer\nfrom tensorflow.keras.applications import DenseNet121 # Keras Application\nfrom tensorflow.keras.layers import Dense # Dense Layer (Fully connected)\nfrom tensorflow.keras.models import Model # Model Structure\n\n\n\ninput_shape=(400, 400, 3)\n\nimg_input = Input(shape=input_shape)\nbase_model = DenseNet121(include_top=False, \n                         input_tensor=img_input, \n                         input_shape=input_shape, \n                         pooling=\"max\", \n                         weights='imagenet')\nbase_model.trainable = True\nx = base_model.output\npredictions = Dense(5, \n                    activation=\"softmax\", \n                    name=\"predictions\")(x)\nmodel = Model(inputs=img_input, \n              outputs=predictions)","metadata":{"papermill":{"duration":5.20005,"end_time":"2020-12-28T01:15:16.757713","exception":false,"start_time":"2020-12-28T01:15:11.557663","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:54.086774Z","iopub.execute_input":"2022-01-29T09:07:54.087477Z","iopub.status.idle":"2022-01-29T09:07:57.038753Z","shell.execute_reply.started":"2022-01-29T09:07:54.087436Z","shell.execute_reply":"2022-01-29T09:07:57.037977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001), #by default learning_rate=0.001\n    loss='categorical_crossentropy',\n    metrics=[tf.keras.metrics.CategoricalAccuracy(name=\"cat_acc\"),tf.keras.metrics.AUC(name='auc'),\n            tf.keras.metrics.Recall(name='recall'),tf.keras.metrics.Precision(name='precision')]\n)","metadata":{"papermill":{"duration":0.135119,"end_time":"2020-12-28T01:15:17.015418","exception":false,"start_time":"2020-12-28T01:15:16.880299","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:57.039993Z","iopub.execute_input":"2022-01-29T09:07:57.040541Z","iopub.status.idle":"2022-01-29T09:07:57.077009Z","shell.execute_reply.started":"2022-01-29T09:07:57.040502Z","shell.execute_reply":"2022-01-29T09:07:57.076254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train Model","metadata":{"papermill":{"duration":0.072989,"end_time":"2020-12-28T01:15:17.164218","exception":false,"start_time":"2020-12-28T01:15:17.091229","status":"completed"},"tags":[]}},{"cell_type":"code","source":"history = model.fit(\n    ds_train,\n    epochs=20,\n    #steps_per_epoch=NUM_TRAIN_IMAGES/32, los batchs de 32 ya han sido asignados arriba\n    validation_data=ds_val,\n    #validation_steps=NUM_VAL_IMAGES/32,\n    class_weight=class_weights_dict,\n    shuffle=True,\n    callbacks=[\n        #tf.keras.callbacks.EarlyStopping(patience=11, verbose=1),\n        tf.keras.callbacks.ReduceLROnPlateau(patience=4, verbose=1),\n        tf.keras.callbacks.ModelCheckpoint(filepath='bestmodel.h5',\n                                          verbose=1, save_best_only=True)\n    ]\n)","metadata":{"papermill":{"duration":17116.709892,"end_time":"2020-12-28T06:00:33.950257","exception":false,"start_time":"2020-12-28T01:15:17.240365","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T09:07:57.078337Z","iopub.execute_input":"2022-01-29T09:07:57.078604Z","iopub.status.idle":"2022-01-29T13:11:31.589227Z","shell.execute_reply.started":"2022-01-29T09:07:57.078569Z","shell.execute_reply":"2022-01-29T13:11:31.587526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot model training","metadata":{"papermill":{"duration":8.260378,"end_time":"2020-12-28T06:00:50.738298","exception":false,"start_time":"2020-12-28T06:00:42.47792","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Se realiza un gráfico de la precisión de entrenamiento y validación\nimport matplotlib.pyplot as plt\nauc = history.history['auc']\nval_auc = history.history['val_auc']\nloss = history.history['loss']\nval_loss = history.history['val_loss']\ncat_acc = history.history['cat_acc']\nval_cat_acc = history.history['val_cat_acc']\n\nepochs = range(len(auc))\nplt.figure(figsize=(18, 4.8))\nplt.subplot(1,3,1)\nplt.plot(epochs, auc, 'r', label='Training auc')\nplt.plot(epochs, val_auc, 'b', label='Validation auc')\nplt.ylim(0, 1)\nplt.title('Training and validation AUC')\nplt.legend(loc=0)\n\nplt.subplot(1,3,2)\nplt.plot(epochs, loss, 'y-.', label='Training loss')\nplt.plot(epochs, val_loss, 'g-.', label='Validation loss')\nplt.title('Training and validation Loss')\nplt.ylim(0, 2)\nplt.legend(loc=0)\n\nplt.subplot(1,3,3)\nplt.plot(epochs, cat_acc, 'c-.', label='Training cat_acc')\nplt.plot(epochs, val_cat_acc, 'g', label='Validation cat_acc')\nplt.title('Training and validation cat_acc')\nplt.ylim(0, 1)\nplt.legend(loc=0)\n\n\n\nplt.show();","metadata":{"papermill":{"duration":8.775656,"end_time":"2020-12-28T06:01:07.117355","exception":false,"start_time":"2020-12-28T06:00:58.341699","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:11:31.594736Z","iopub.execute_input":"2022-01-29T13:11:31.595219Z","iopub.status.idle":"2022-01-29T13:11:32.142394Z","shell.execute_reply.started":"2022-01-29T13:11:31.595158Z","shell.execute_reply":"2022-01-29T13:11:32.141638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Only use the best weights for the model.","metadata":{"papermill":{"duration":7.847463,"end_time":"2020-12-28T06:01:22.82921","exception":false,"start_time":"2020-12-28T06:01:14.981747","status":"completed"},"tags":[]}},{"cell_type":"code","source":"best_model = tf.keras.models.load_model('bestmodel.h5')","metadata":{"papermill":{"duration":14.662983,"end_time":"2020-12-28T06:01:45.174541","exception":false,"start_time":"2020-12-28T06:01:30.511558","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:11:32.143935Z","iopub.execute_input":"2022-01-29T13:11:32.144185Z","iopub.status.idle":"2022-01-29T13:11:36.412367Z","shell.execute_reply.started":"2022-01-29T13:11:32.144149Z","shell.execute_reply":"2022-01-29T13:11:36.411564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preds and Evaluation","metadata":{"papermill":{"duration":7.774795,"end_time":"2020-12-28T06:02:00.645527","exception":false,"start_time":"2020-12-28T06:01:52.870732","status":"completed"},"tags":[]}},{"cell_type":"code","source":"preds = best_model.predict(ds_test, verbose=1)","metadata":{"papermill":{"duration":223.0453,"end_time":"2020-12-28T06:05:51.725356","exception":false,"start_time":"2020-12-28T06:02:08.680056","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:11:36.414482Z","iopub.execute_input":"2022-01-29T13:11:36.414690Z","iopub.status.idle":"2022-01-29T13:14:41.980976Z","shell.execute_reply.started":"2022-01-29T13:11:36.414664Z","shell.execute_reply":"2022-01-29T13:14:41.980249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"evaluation_model = best_model.evaluate(ds_test, verbose=1)","metadata":{"papermill":{"duration":218.653469,"end_time":"2020-12-28T06:09:39.281321","exception":false,"start_time":"2020-12-28T06:06:00.627852","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:14:41.982969Z","iopub.execute_input":"2022-01-29T13:14:41.983266Z","iopub.status.idle":"2022-01-29T13:18:05.991876Z","shell.execute_reply.started":"2022-01-29T13:14:41.983181Z","shell.execute_reply":"2022-01-29T13:18:05.990974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(*zip(evaluation_model,['loss','cat_acc','auc','recall','precision']))","metadata":{"papermill":{"duration":9.398755,"end_time":"2020-12-28T06:09:58.247539","exception":false,"start_time":"2020-12-28T06:09:48.848784","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:05.993858Z","iopub.execute_input":"2022-01-29T13:18:05.994728Z","iopub.status.idle":"2022-01-29T13:18:06.000740Z","shell.execute_reply.started":"2022-01-29T13:18:05.994683Z","shell.execute_reply":"2022-01-29T13:18:06.000039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds[1]","metadata":{"papermill":{"duration":8.964382,"end_time":"2020-12-28T06:10:15.940978","exception":false,"start_time":"2020-12-28T06:10:06.976596","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:06.001832Z","iopub.execute_input":"2022-01-29T13:18:06.004422Z","iopub.status.idle":"2022-01-29T13:18:06.014223Z","shell.execute_reply.started":"2022-01-29T13:18:06.004364Z","shell.execute_reply":"2022-01-29T13:18:06.013346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = [np.argmax(pred) for pred in preds]","metadata":{"papermill":{"duration":9.156625,"end_time":"2020-12-28T06:10:34.671728","exception":false,"start_time":"2020-12-28T06:10:25.515103","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:06.016293Z","iopub.execute_input":"2022-01-29T13:18:06.016709Z","iopub.status.idle":"2022-01-29T13:18:06.128608Z","shell.execute_reply.started":"2022-01-29T13:18:06.016665Z","shell.execute_reply":"2022-01-29T13:18:06.127808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(preds)","metadata":{"papermill":{"duration":9.772327,"end_time":"2020-12-28T06:10:54.263472","exception":false,"start_time":"2020-12-28T06:10:44.491145","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:06.130057Z","iopub.execute_input":"2022-01-29T13:18:06.130326Z","iopub.status.idle":"2022-01-29T13:18:06.136309Z","shell.execute_reply.started":"2022-01-29T13:18:06.130292Z","shell.execute_reply":"2022-01-29T13:18:06.135442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ds_test = ds_test.unbatch()","metadata":{"papermill":{"duration":8.953033,"end_time":"2020-12-28T06:11:12.240494","exception":false,"start_time":"2020-12-28T06:11:03.287461","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:06.137857Z","iopub.execute_input":"2022-01-29T13:18:06.138381Z","iopub.status.idle":"2022-01-29T13:18:06.154165Z","shell.execute_reply.started":"2022-01-29T13:18:06.138343Z","shell.execute_reply":"2022-01-29T13:18:06.153402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"actuals = [np.argmax(row[1]) for row in ds_test.as_numpy_iterator()]","metadata":{"papermill":{"duration":154.736414,"end_time":"2020-12-28T06:13:55.885854","exception":false,"start_time":"2020-12-28T06:11:21.14944","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:18:06.155806Z","iopub.execute_input":"2022-01-29T13:18:06.156310Z","iopub.status.idle":"2022-01-29T13:20:02.528797Z","shell.execute_reply.started":"2022-01-29T13:18:06.156273Z","shell.execute_reply":"2022-01-29T13:20:02.527926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(actuals)","metadata":{"papermill":{"duration":9.253645,"end_time":"2020-12-28T06:14:14.219481","exception":false,"start_time":"2020-12-28T06:14:04.965836","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:20:02.532048Z","iopub.execute_input":"2022-01-29T13:20:02.532340Z","iopub.status.idle":"2022-01-29T13:20:02.538533Z","shell.execute_reply.started":"2022-01-29T13:20:02.532298Z","shell.execute_reply":"2022-01-29T13:20:02.537854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"preds:\",preds[:30])\nprint(\"trues:\",actuals[:30])","metadata":{"papermill":{"duration":8.793393,"end_time":"2020-12-28T06:14:31.777648","exception":false,"start_time":"2020-12-28T06:14:22.984255","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:20:02.539782Z","iopub.execute_input":"2022-01-29T13:20:02.540161Z","iopub.status.idle":"2022-01-29T13:20:02.551659Z","shell.execute_reply.started":"2022-01-29T13:20:02.540124Z","shell.execute_reply":"2022-01-29T13:20:02.550903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_weights = compute_sample_weight('balanced', actuals)","metadata":{"papermill":{"duration":9.680079,"end_time":"2020-12-28T06:14:51.269977","exception":false,"start_time":"2020-12-28T06:14:41.589898","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:20:02.552892Z","iopub.execute_input":"2022-01-29T13:20:02.553304Z","iopub.status.idle":"2022-01-29T13:20:02.577768Z","shell.execute_reply.started":"2022-01-29T13:20:02.553263Z","shell.execute_reply":"2022-01-29T13:20:02.577085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"m = tfa.metrics.CohenKappa(num_classes=5, sparse_labels=True, weightage=\"quadratic\")\n#m = tf.keras.metrics.Accuracy()\nm.update_state(actuals, preds, sample_weight=sample_weights)\nprint('Final result: ', m.result().numpy())","metadata":{"papermill":{"duration":1229.112279,"end_time":"2020-12-28T06:35:29.392935","exception":false,"start_time":"2020-12-28T06:15:00.280656","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:20:02.579020Z","iopub.execute_input":"2022-01-29T13:20:02.579422Z","iopub.status.idle":"2022-01-29T13:32:09.652344Z","shell.execute_reply.started":"2022-01-29T13:20:02.579386Z","shell.execute_reply":"2022-01-29T13:32:09.651432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import (mean_squared_error,confusion_matrix, plot_confusion_matrix, f1_score)\nfrom sklearn.metrics import classification_report\n\ntarget_names = ['class 0', 'class 1', 'class 2', 'class 3', 'class 4']\nprint(classification_report(actuals, preds, target_names=target_names))","metadata":{"papermill":{"duration":9.930679,"end_time":"2020-12-28T06:35:49.557577","exception":false,"start_time":"2020-12-28T06:35:39.626898","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:32:09.653711Z","iopub.execute_input":"2022-01-29T13:32:09.654443Z","iopub.status.idle":"2022-01-29T13:32:09.726388Z","shell.execute_reply.started":"2022-01-29T13:32:09.654397Z","shell.execute_reply":"2022-01-29T13:32:09.725601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"confusion_matrix(actuals, preds)","metadata":{"papermill":{"duration":9.680681,"end_time":"2020-12-28T06:36:08.260899","exception":false,"start_time":"2020-12-28T06:35:58.580218","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-01-29T13:32:09.727590Z","iopub.execute_input":"2022-01-29T13:32:09.728446Z","iopub.status.idle":"2022-01-29T13:32:09.792776Z","shell.execute_reply.started":"2022-01-29T13:32:09.728406Z","shell.execute_reply":"2022-01-29T13:32:09.791940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":9.311582,"end_time":"2020-12-28T06:36:26.786524","exception":false,"start_time":"2020-12-28T06:36:17.474942","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}