{"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":"markdown","source":"## Projet  DeepL : M2 - S1 - IA School","metadata":{}},{"cell_type":"markdown","source":"### Sujet 2 : Human Protein Atlas\nHuman Protein Atlas Image Classification | Kaggle\n\nhttps://www.kaggle.com/competitions/human-protein-atlas-image-classification/overview","metadata":{}},{"cell_type":"markdown","source":"## Réalisé par : \n**Djambala GORY - Farikou RAPHIOU - Awa DIALLO - Peniel MMEN - Arieh ALLOUCHE**","metadata":{}},{"cell_type":"markdown","source":"### **Classer les modèles de protéines subcellulaires dans les cellules humaines**","metadata":{}},{"cell_type":"markdown","source":"## Introduction","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"## Installation de packages","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom PIL import Image\nimport pathlib as p\nimport matplotlib.pyplot as plt\nimport os\nimport keras\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nimport cv2\nfrom keras import applications\nfrom keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, Input\nfrom tensorflow.keras.losses import SparseCategoricalCrossentropy\nfrom keras.models import Model\nfrom keras.optimizers import *","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:32:31.657365Z","iopub.execute_input":"2023-01-27T08:32:31.65775Z","iopub.status.idle":"2023-01-27T08:32:38.253818Z","shell.execute_reply.started":"2023-01-27T08:32:31.657709Z","shell.execute_reply":"2023-01-27T08:32:38.252842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Chargement et prétraitement de données","metadata":{}},{"cell_type":"markdown","source":"Le format de données est double - premièrement, les étiquettes sont fournies pour chaque échantillon dans train.csv .\n\nLa majeure partie des données se trouve dans les images - train.zip et test.zip . Dans chacun d'eux se trouve un dossier contenant quatre fichiers par échantillon. Chaque fichier représente un filtre différent sur les modèles de protéines subcellulaires représentés par l'échantillon. Le format doit être [filename]_[filter color].pngpour les fichiers PNG","metadata":{}},{"cell_type":"code","source":"csv_dataset_train = pd.read_csv(\"/kaggle/input/human-protein-atlas-image-classification/train.csv\") # Training\ncsv_dataset_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:32:46.528458Z","iopub.execute_input":"2023-01-27T08:32:46.529101Z","iopub.status.idle":"2023-01-27T08:32:46.601841Z","shell.execute_reply.started":"2023-01-27T08:32:46.529064Z","shell.execute_reply":"2023-01-27T08:32:46.600823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_dataset_test = pd.read_csv(\"/kaggle/input/human-protein-atlas-image-classification/sample_submission.csv\") # Training\ncsv_dataset_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:32:53.921942Z","iopub.execute_input":"2023-01-27T08:32:53.922362Z","iopub.status.idle":"2023-01-27T08:32:53.952157Z","shell.execute_reply.started":"2023-01-27T08:32:53.922328Z","shell.execute_reply":"2023-01-27T08:32:53.951189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(csv_dataset_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:56:27.677403Z","iopub.execute_input":"2023-01-27T09:56:27.677828Z","iopub.status.idle":"2023-01-27T09:56:27.684241Z","shell.execute_reply.started":"2023-01-27T09:56:27.677793Z","shell.execute_reply":"2023-01-27T09:56:27.683193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(csv_dataset_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:43:50.251473Z","iopub.execute_input":"2023-01-26T22:43:50.255154Z","iopub.status.idle":"2023-01-26T22:43:50.268165Z","shell.execute_reply.started":"2023-01-26T22:43:50.255098Z","shell.execute_reply":"2023-01-26T22:43:50.267186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = csv_dataset_train['Target']\ntarget.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:33:09.009029Z","iopub.execute_input":"2023-01-27T08:33:09.009381Z","iopub.status.idle":"2023-01-27T08:33:09.020881Z","shell.execute_reply.started":"2023-01-27T08:33:09.009351Z","shell.execute_reply":"2023-01-27T08:33:09.019883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IDs = csv_dataset_train['Id']\nplt.figure(figsize = (17, 12))\nfor i in range(20):\n  plt.subplot(4, 5, i + 1)\n  red= cv2.imread(\"/kaggle/input/human-protein-atlas-image-classification/train/{}_red.png\".format(str(IDs[i])), 0)\n  green = cv2.imread(\"/kaggle/input/human-protein-atlas-image-classification/train/{}_green.png\".format(str(IDs[i])), 0)\n  blue = cv2.imread(\"/kaggle/input/human-protein-atlas-image-classification/train/{}_blue.png\".format(str(IDs[i])), 0)\n  image = np.stack((red, green, blue), -1)\n  plt.imshow(image)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:33:22.144122Z","iopub.execute_input":"2023-01-27T08:33:22.144493Z","iopub.status.idle":"2023-01-27T08:33:25.533605Z","shell.execute_reply.started":"2023-01-27T08:33:22.144462Z","shell.execute_reply":"2023-01-27T08:33:25.532607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def reszie_and_scale_image(img, target_size):\n  img = cv2.resize(img, target_size)\n  img = img/255\n  return img","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:33:35.056124Z","iopub.execute_input":"2023-01-27T08:33:35.056502Z","iopub.status.idle":"2023-01-27T08:33:35.062183Z","shell.execute_reply.started":"2023-01-27T08:33:35.056472Z","shell.execute_reply":"2023-01-27T08:33:35.061135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_img(paths):\n  red = cv2.imread(paths[0], 0)\n  red = reszie_and_scale_image(red, (90, 90))\n  blue = cv2.imread(paths[1], 0)\n  blue = reszie_and_scale_image(blue, (90, 90))\n  yellow = cv2.imread(paths[2])\n  yellow = reszie_and_scale_image(yellow, (90, 90))\n  green = cv2.imread(paths[3], 0)\n  green = reszie_and_scale_image(green, (90, 90))\n  return np.array([np.stack(\n      (red, green, blue), -1\n  ), yellow])","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:34:05.085982Z","iopub.execute_input":"2023-01-27T08:34:05.08638Z","iopub.status.idle":"2023-01-27T08:34:05.093379Z","shell.execute_reply.started":"2023-01-27T08:34:05.086345Z","shell.execute_reply":"2023-01-27T08:34:05.092305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_dataset_train_new = csv_dataset_train.head(10000) # csv_dataset.sample(frac=0.3) \ncsv_dataset_train_new.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:30:40.755973Z","iopub.execute_input":"2023-01-27T09:30:40.757047Z","iopub.status.idle":"2023-01-27T09:30:40.768421Z","shell.execute_reply.started":"2023-01-27T09:30:40.757007Z","shell.execute_reply":"2023-01-27T09:30:40.767318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_dataset_test_new = csv_dataset_test.head(1000) # csv_dataset.sample(frac=0.3) \ncsv_dataset_test_new.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:04:10.006887Z","iopub.execute_input":"2023-01-27T09:04:10.00801Z","iopub.status.idle":"2023-01-27T09:04:10.018632Z","shell.execute_reply.started":"2023-01-27T09:04:10.007963Z","shell.execute_reply":"2023-01-27T09:04:10.017296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_train = []\nlist_images_csv_dataset = csv_dataset_train_new['Id']\nfor img in list_images_csv_dataset:\n  arr = read_img([\n      \"/kaggle/input/human-protein-atlas-image-classification/train/{}_red.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/train/{}_blue.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/train/{}_yellow.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/train/{}_green.png\".format(str(img))\n  ])\n  images_train.append(arr)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:30:48.237968Z","iopub.execute_input":"2023-01-27T09:30:48.238406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_test = []\nlist_images_csv_dataset = csv_dataset_test_new['Id']\nfor img in list_images_csv_dataset:\n  arr = read_img([\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_red.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_blue.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_yellow.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_green.png\".format(str(img))\n  ])\n  images_test.append(arr)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:52:24.687826Z","iopub.execute_input":"2023-01-26T22:52:24.688654Z","iopub.status.idle":"2023-01-26T22:53:04.073762Z","shell.execute_reply.started":"2023-01-26T22:52:24.688614Z","shell.execute_reply":"2023-01-26T22:53:04.072692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_train = np.asarray(images_train)\nimages_train.shape\nimages_train[0][0].shape","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:36:59.097121Z","iopub.execute_input":"2023-01-27T09:36:59.097442Z","iopub.status.idle":"2023-01-27T09:36:59.105524Z","shell.execute_reply.started":"2023-01-27T09:36:59.097413Z","shell.execute_reply":"2023-01-27T09:36:59.104463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_test = np.asarray(images_test)\nimages_test.shape\nimages_test[0][0].shape","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:53:42.236186Z","iopub.execute_input":"2023-01-26T22:53:42.237329Z","iopub.status.idle":"2023-01-26T22:53:42.353571Z","shell.execute_reply.started":"2023-01-26T22:53:42.237284Z","shell.execute_reply":"2023-01-26T22:53:42.352305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (17, 12))\nfor i in range(24):\n  plt.subplot(4, 6, i + 1)\n  plt.imshow(images_train[i][0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:06.557214Z","iopub.execute_input":"2023-01-27T09:37:06.558752Z","iopub.status.idle":"2023-01-27T09:37:09.015025Z","shell.execute_reply.started":"2023-01-27T09:37:06.558699Z","shell.execute_reply":"2023-01-27T09:37:09.00916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12, 4))\ncolors = [\"rgb\", \"yellow\"]\nfor i in range(2):\n  plt.subplot(1, 4, i + 1)\n  plt.imshow(images_train[1][i])\n  plt.title(colors[i])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:15.296013Z","iopub.execute_input":"2023-01-27T09:37:15.296384Z","iopub.status.idle":"2023-01-27T09:37:15.570788Z","shell.execute_reply.started":"2023-01-27T09:37:15.296353Z","shell.execute_reply":"2023-01-27T09:37:15.569843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_after = np.zeros((len(csv_dataset_train_new), 28), dtype=int)\ntarget_after.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:29.81628Z","iopub.execute_input":"2023-01-27T09:37:29.816671Z","iopub.status.idle":"2023-01-27T09:37:29.826036Z","shell.execute_reply.started":"2023-01-27T09:37:29.816628Z","shell.execute_reply":"2023-01-27T09:37:29.82508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_after = np.zeros((len(csv_dataset_test_new), 28), dtype=int)\npredicted_after.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:54:24.427579Z","iopub.execute_input":"2023-01-26T22:54:24.428004Z","iopub.status.idle":"2023-01-26T22:54:24.437353Z","shell.execute_reply.started":"2023-01-26T22:54:24.427969Z","shell.execute_reply":"2023-01-26T22:54:24.436037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_after[0]","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:35.237974Z","iopub.execute_input":"2023-01-27T09:37:35.238415Z","iopub.status.idle":"2023-01-27T09:37:35.249589Z","shell.execute_reply.started":"2023-01-27T09:37:35.238375Z","shell.execute_reply":"2023-01-27T09:37:35.248114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_after[0]","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:54:37.005272Z","iopub.execute_input":"2023-01-26T22:54:37.005655Z","iopub.status.idle":"2023-01-26T22:54:37.012186Z","shell.execute_reply.started":"2023-01-26T22:54:37.005624Z","shell.execute_reply":"2023-01-26T22:54:37.011184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targets = csv_dataset_train_new['Target']\nfor index, tar in enumerate(targets):\n  ids = tar.split()\n  for id in ids:\n    target_after[index, int(id)] = 1","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:40.612597Z","iopub.execute_input":"2023-01-27T09:37:40.612998Z","iopub.status.idle":"2023-01-27T09:37:40.637468Z","shell.execute_reply.started":"2023-01-27T09:37:40.612965Z","shell.execute_reply":"2023-01-27T09:37:40.636368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"csv_dataset_test_new['Predicted'] = csv_dataset_test_new['Predicted'].astype(str)\npredicted = csv_dataset_test_new['Predicted']\nfor index, tar in enumerate(predicted):\n  ids = tar.split()\n  for id in ids:\n    predicted_after[index, int(id)] = 1","metadata":{"execution":{"iopub.status.busy":"2023-01-27T08:41:33.862585Z","iopub.execute_input":"2023-01-27T08:41:33.862963Z","iopub.status.idle":"2023-01-27T08:41:34.104012Z","shell.execute_reply.started":"2023-01-27T08:41:33.862929Z","shell.execute_reply":"2023-01-27T08:41:34.102693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_after[0]","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:48.20856Z","iopub.execute_input":"2023-01-27T09:37:48.208948Z","iopub.status.idle":"2023-01-27T09:37:48.217727Z","shell.execute_reply.started":"2023-01-27T09:37:48.208915Z","shell.execute_reply":"2023-01-27T09:37:48.216666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_after[0]","metadata":{"execution":{"iopub.status.busy":"2023-01-26T22:54:54.881786Z","iopub.execute_input":"2023-01-26T22:54:54.883312Z","iopub.status.idle":"2023-01-26T22:54:54.892427Z","shell.execute_reply.started":"2023-01-26T22:54:54.883275Z","shell.execute_reply":"2023-01-26T22:54:54.891338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DenseNet_model = tf.keras.applications.DenseNet201(include_top=False, weights='imagenet',input_shape = (90, 90, 3))","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:37:55.181731Z","iopub.execute_input":"2023-01-27T09:37:55.182418Z","iopub.status.idle":"2023-01-27T09:38:00.640155Z","shell.execute_reply.started":"2023-01-27T09:37:55.182381Z","shell.execute_reply":"2023-01-27T09:38:00.639127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"VGG16_model = tf.keras.applications.VGG16(include_top=False, weights='imagenet',input_shape = (90, 90, 3))","metadata":{"execution":{"iopub.status.busy":"2023-01-27T01:47:29.834239Z","iopub.execute_input":"2023-01-27T01:47:29.834627Z","iopub.status.idle":"2023-01-27T01:47:30.110171Z","shell.execute_reply.started":"2023-01-27T01:47:29.834595Z","shell.execute_reply":"2023-01-27T01:47:30.109033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ResNet50_model = tf.keras.applications.ResNet50(include_top=False, weights='imagenet',input_shape = (90, 90, 3))","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:07:38.491048Z","iopub.execute_input":"2023-01-27T09:07:38.491416Z","iopub.status.idle":"2023-01-27T09:07:39.800271Z","shell.execute_reply.started":"2023-01-27T09:07:38.491386Z","shell.execute_reply":"2023-01-27T09:07:39.799278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in DenseNet_model.layers:\n  layer.trainable = True  \nmodel = tf.keras.models.Sequential([\n    tf.keras.layers.TimeDistributed(DenseNet_model, input_shape = (2, 90, 90, 3)),\n    tf.keras.layers.TimeDistributed(tf.keras.layers.Dropout(0.5)),\n    tf.keras.layers.TimeDistributed(tf.keras.layers.GlobalAveragePooling2D()),\n    tf.keras.layers.GlobalAveragePooling1D(name = \"GlobalAveragePooling1D\"),\n    tf.keras.layers.BatchNormalization(name = \"BatchNormalization\"),\n    tf.keras.layers.Dropout(0.5),\n    tf.keras.layers.Dense(128, activation = \"relu\"),\n    tf.keras.layers.Dropout(0.5),\n    tf.keras.layers.Dense(28, activation=\"sigmoid\")\n])","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:38:05.69833Z","iopub.execute_input":"2023-01-27T09:38:05.698697Z","iopub.status.idle":"2023-01-27T09:38:08.027943Z","shell.execute_reply.started":"2023-01-27T09:38:05.698666Z","shell.execute_reply":"2023-01-27T09:38:08.026962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer = tf.keras.optimizers.Adam(learning_rate=0.00001), loss = \"binary_crossentropy\" ,\n              metrics = [\"binary_accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:38:12.737501Z","iopub.execute_input":"2023-01-27T09:38:12.738251Z","iopub.status.idle":"2023-01-27T09:38:12.760827Z","shell.execute_reply.started":"2023-01-27T09:38:12.738203Z","shell.execute_reply":"2023-01-27T09:38:12.759808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.00001),loss=tf.keras.losses.sparse_categorical_crossentropy,metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2023-01-26T20:27:31.102122Z","iopub.execute_input":"2023-01-26T20:27:31.102535Z","iopub.status.idle":"2023-01-26T20:27:31.130462Z","shell.execute_reply.started":"2023-01-26T20:27:31.102504Z","shell.execute_reply":"2023-01-26T20:27:31.129548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:38:19.747928Z","iopub.execute_input":"2023-01-27T09:38:19.748884Z","iopub.status.idle":"2023-01-27T09:38:19.789256Z","shell.execute_reply.started":"2023-01-27T09:38:19.748845Z","shell.execute_reply":"2023-01-27T09:38:19.788218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model, show_shapes=True,)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T20:49:52.834758Z","iopub.execute_input":"2023-01-26T20:49:52.835747Z","iopub.status.idle":"2023-01-26T20:49:54.41003Z","shell.execute_reply.started":"2023-01-26T20:49:52.835708Z","shell.execute_reply":"2023-01-26T20:49:54.408858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from keras.callbacks import EarlyStopping\n#es = EarlyStopping(monitor='val_loss', verbose=1, patience=5)\n#model.fit((images_train,  target_after), validation_data=(images_test, predicted_after), epochs=10, callbacks=[es])","metadata":{"execution":{"iopub.status.busy":"2023-01-26T23:17:00.526438Z","iopub.execute_input":"2023-01-26T23:17:00.526989Z","iopub.status.idle":"2023-01-26T23:17:00.532417Z","shell.execute_reply.started":"2023-01-26T23:17:00.526944Z","shell.execute_reply":"2023-01-26T23:17:00.531175Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    images_train, target_after, epochs = 10, batch_size = 32,\n          validation_split = 0.1,\n          callbacks = [tf.keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.1, mode = 'min',patience= 1),\n              tf.keras.callbacks.EarlyStopping(patience = 7, monitor = 'val_loss', mode = 'min', restore_best_weights=True)]\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:38:39.223546Z","iopub.execute_input":"2023-01-27T09:38:39.223961Z","iopub.status.idle":"2023-01-27T09:52:59.220048Z","shell.execute_reply.started":"2023-01-27T09:38:39.223923Z","shell.execute_reply":"2023-01-27T09:52:59.218961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"figures = ['loss', \"binary_accuracy\"]\ntitles = [\"loss vs (validation loss)\", \"accuracy vs (validation accuracy)\"] \nplt.figure(figsize = (20, 5))\nfor i in range(2):\n  plt.subplot(1, 2, (i + 1))\n  plt.title(titles[i])\n  plt.plot(history.history[figures[i]])\n  plt.plot(history.history['val_{}'.format(figures[i])])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-27T09:54:14.445995Z","iopub.execute_input":"2023-01-27T09:54:14.446415Z","iopub.status.idle":"2023-01-27T09:54:14.742396Z","shell.execute_reply.started":"2023-01-27T09:54:14.446382Z","shell.execute_reply":"2023-01-27T09:54:14.741189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss, accuracy = model.evaluate(images_train, target_after)\nprint(\"Loss :\", loss)\nprint(\"Accuracy :\", accuracy)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T10:43:39.785519Z","iopub.execute_input":"2023-01-27T10:43:39.785981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict_ds = tf.data.Dataset.from_tensor_slices(images_train).batch(32)\nresult = model.predict(predict_ds, steps = 10)\nprint(result.shape)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = model.predict(images_train, target_after, steps = 10)\nprint(result.shape)","metadata":{"execution":{"iopub.status.busy":"2023-01-27T01:20:51.221043Z","iopub.execute_input":"2023-01-27T01:20:51.221489Z","iopub.status.idle":"2023-01-27T01:20:51.28786Z","shell.execute_reply.started":"2023-01-27T01:20:51.221454Z","shell.execute_reply":"2023-01-27T01:20:51.286823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test sur le modèle","metadata":{}},{"cell_type":"code","source":"imagesTest = []\nlist_images_csv_dataset = csv_dataset_new['Id']\nfor img in list_images_csv_dataset:\n  arr = read_img([\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_red.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_blue.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_yellow.png\".format(str(img)),\n      \"/kaggle/input/human-protein-atlas-image-classification/test/{}_green.png\".format(str(img))\n  ])\n  imagesTest.append(arr)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imagesTest = np.asarray(imagesTest)\nimagesTest.shape\nimagesTest[0][0].shape","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (17, 12))\nfor i in range(24):\n  plt.subplot(4, 6, i + 1)\n  plt.imshow(images[i][0])\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (12, 4))\ncolors = [\"rgb\", \"yellow\"]\nfor i in range(2):\n  plt.subplot(1, 4, i + 1)\n  plt.imshow(images[1][i])\n  plt.title(colors[i])\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"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":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-01-26T16:20:56.543826Z","iopub.execute_input":"2023-01-26T16:20:56.544232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}