{"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":"import os\nimport shutil\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nimport cv2 as cv\nfrom numpy.random import seed\nseed(45)\nimport pickle\n\nfrom sklearn.utils import shuffle\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.model_selection import train_test_split\nimport tensorflow as tf\nfrom tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import *\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom glob import glob \n%matplotlib inline","metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","execution":{"iopub.status.busy":"2021-11-07T20:35:10.338765Z","iopub.execute_input":"2021-11-07T20:35:10.339103Z","iopub.status.idle":"2021-11-07T20:35:10.354547Z","shell.execute_reply.started":"2021-11-07T20:35:10.339069Z","shell.execute_reply":"2021-11-07T20:35:10.353429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dirname = '/kaggle/input/histopathologic-cancer-detection/train'","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:35.406507Z","iopub.execute_input":"2021-11-07T20:00:35.407041Z","iopub.status.idle":"2021-11-07T20:00:35.411915Z","shell.execute_reply.started":"2021-11-07T20:00:35.406997Z","shell.execute_reply":"2021-11-07T20:00:35.410869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Dataset exploration","metadata":{}},{"cell_type":"code","source":"train_labels = pd.read_csv('/kaggle/input/histopathologic-cancer-detection/train_labels.csv')\ntrain_labels.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:35.413639Z","iopub.execute_input":"2021-11-07T20:00:35.413997Z","iopub.status.idle":"2021-11-07T20:00:35.870031Z","shell.execute_reply.started":"2021-11-07T20:00:35.413955Z","shell.execute_reply":"2021-11-07T20:00:35.867953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Label distribution","metadata":{}},{"cell_type":"code","source":"train_labels['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:35.871488Z","iopub.execute_input":"2021-11-07T20:00:35.871885Z","iopub.status.idle":"2021-11-07T20:00:35.889004Z","shell.execute_reply.started":"2021-11-07T20:00:35.871829Z","shell.execute_reply":"2021-11-07T20:00:35.888298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display a DataFrame showing the proportion of observations with each \n# possible of the target variable (which is label). \n(train_labels.label.value_counts() / len(train_labels)).to_frame()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:35.892020Z","iopub.execute_input":"2021-11-07T20:00:35.892732Z","iopub.status.idle":"2021-11-07T20:00:36.033344Z","shell.execute_reply.started":"2021-11-07T20:00:35.892673Z","shell.execute_reply":"2021-11-07T20:00:36.032559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels.info()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:36.035660Z","iopub.execute_input":"2021-11-07T20:00:36.036168Z","iopub.status.idle":"2021-11-07T20:00:36.069482Z","shell.execute_reply.started":"2021-11-07T20:00:36.036120Z","shell.execute_reply":"2021-11-07T20:00:36.068299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Data is not entirely balanced, there is more negative samples than positive, by about 30 percent","metadata":{}},{"cell_type":"markdown","source":"# View Sample Images","metadata":{}},{"cell_type":"code","source":"positive_samples = train_labels.loc[train_labels['label'] == 1].sample(4)\nnegative_samples = train_labels.loc[train_labels['label'] == 0].sample(4)\npositive_images = []\nnegative_images = []\nfor sample in positive_samples['id']:\n    path = os.path.join(train_dirname, sample+'.tif')\n    img = cv.imread(path)\n    positive_images.append(img)\n        \nfor sample in negative_samples['id']:\n    path = os.path.join(train_dirname, sample+'.tif')\n    img = cv.imread(path)\n    negative_images.append(img)\n\nfig,axis = plt.subplots(2,4,figsize=(20,8))\nfig.suptitle('Dataset samples presentation plot',fontsize=20)\nfor i,img in enumerate(positive_images):\n    axis[0,i].imshow(img)\n    rect = patches.Rectangle((32,32),32,32,linewidth=4,edgecolor='g',facecolor='none', linestyle=':', capstyle='round')\n    axis[0,i].add_patch(rect)\naxis[0,0].set_ylabel('Positive samples', size='large')\nfor i,img in enumerate(negative_images):\n    axis[1,i].imshow(img)\n    rect = patches.Rectangle((32,32),32,32,linewidth=4,edgecolor='r',facecolor='none', linestyle=':', capstyle='round')\n    axis[1,i].add_patch(rect)\naxis[1,0].set_ylabel('Negative samples', size='large')\n    ","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:36.070961Z","iopub.execute_input":"2021-11-07T20:00:36.071266Z","iopub.status.idle":"2021-11-07T20:00:37.468799Z","shell.execute_reply.started":"2021-11-07T20:00:36.071236Z","shell.execute_reply":"2021-11-07T20:00:37.467607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Splitting dataset","metadata":{}},{"cell_type":"markdown","source":"# Setting up learning constants","metadata":{}},{"cell_type":"code","source":"IMG_SIZE = 96\nIMG_CHANNELS = 3\n#TRAIN_SIZE=80000\nTRAIN_SIZE = 8000\nBATCH_SIZE = 64\nEPOCHS = 30","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.470743Z","iopub.execute_input":"2021-11-07T20:00:37.471041Z","iopub.status.idle":"2021-11-07T20:00:37.475829Z","shell.execute_reply.started":"2021-11-07T20:00:37.471009Z","shell.execute_reply":"2021-11-07T20:00:37.474832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Balancing the dataset","metadata":{}},{"cell_type":"code","source":"train_neg = train_labels[train_labels['label']==0].sample(TRAIN_SIZE,random_state=45)\ntrain_pos = train_labels[train_labels['label']==1].sample(TRAIN_SIZE,random_state=45)\n\ntrain_data = pd.concat([train_neg, train_pos], axis=0).reset_index(drop=True)\n\ntrain_data = shuffle(train_data)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.477080Z","iopub.execute_input":"2021-11-07T20:00:37.477347Z","iopub.status.idle":"2021-11-07T20:00:37.521845Z","shell.execute_reply.started":"2021-11-07T20:00:37.477320Z","shell.execute_reply":"2021-11-07T20:00:37.521157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.523343Z","iopub.execute_input":"2021-11-07T20:00:37.523945Z","iopub.status.idle":"2021-11-07T20:00:37.534717Z","shell.execute_reply.started":"2021-11-07T20:00:37.523900Z","shell.execute_reply":"2021-11-07T20:00:37.533633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def append_ext(fn):\n    return fn+\".tif\"","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.536651Z","iopub.execute_input":"2021-11-07T20:00:37.537002Z","iopub.status.idle":"2021-11-07T20:00:37.544264Z","shell.execute_reply.started":"2021-11-07T20:00:37.536962Z","shell.execute_reply":"2021-11-07T20:00:37.542962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Splitting the dataset","metadata":{}},{"cell_type":"code","source":"#y = train_data['label']\n#train_df, val_df = train_test_split(train_data, test_size=0.3, random_state=45, stratify=y)\n#y = val_df['label']\n#val_df, test_df = train_test_split(val_df, test_size=0.5, random_state=45, stratify=y)\n#print(train_df.shape)\n#print(val_df.shape)\n#print(test_df.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.547274Z","iopub.execute_input":"2021-11-07T20:00:37.547696Z","iopub.status.idle":"2021-11-07T20:00:37.558370Z","shell.execute_reply.started":"2021-11-07T20:00:37.547651Z","shell.execute_reply":"2021-11-07T20:00:37.557396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train_data['label']\ntrain_df, valid_df = train_test_split(train_data, test_size=0.2, random_state=45, stratify=y)\n\nprint(train_df.shape)\nprint(valid_df.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.560073Z","iopub.execute_input":"2021-11-07T20:00:37.560557Z","iopub.status.idle":"2021-11-07T20:00:37.598691Z","shell.execute_reply.started":"2021-11-07T20:00:37.560513Z","shell.execute_reply":"2021-11-07T20:00:37.597565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['id'] = train_df['id'].apply(append_ext)\nvalid_df['id'] = valid_df['id'].apply(append_ext)\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.600299Z","iopub.execute_input":"2021-11-07T20:00:37.600834Z","iopub.status.idle":"2021-11-07T20:00:37.632376Z","shell.execute_reply.started":"2021-11-07T20:00:37.600788Z","shell.execute_reply":"2021-11-07T20:00:37.630987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Image generators for the simple CNN model","metadata":{}},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(rescale=1/255)\nvalid_datagen = ImageDataGenerator(rescale=1/255)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.633593Z","iopub.execute_input":"2021-11-07T20:00:37.634039Z","iopub.status.idle":"2021-11-07T20:00:37.638864Z","shell.execute_reply.started":"2021-11-07T20:00:37.634006Z","shell.execute_reply":"2021-11-07T20:00:37.638199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 64\ntrain_path = '../input/histopathologic-cancer-detection/train'\ntrain_df['label'] = train_df['label'].astype(str)\nvalid_df['label'] = valid_df['label'].astype(str)\n\ntrain_loader = train_datagen.flow_from_dataframe(\n    dataframe = train_df,\n    directory = train_path,\n    x_col = 'id',\n    y_col = 'label',\n    batch_size = BATCH_SIZE,\n    seed = 1,\n    shuffle = True,\n    class_mode = 'categorical',\n    target_size = (32,32)\n)\n\nvalid_loader = valid_datagen.flow_from_dataframe(\n    dataframe = valid_df,\n    directory = train_path,\n    x_col = 'id',\n    y_col = 'label',\n    batch_size = BATCH_SIZE,\n    seed = 1,\n    shuffle = True,\n    class_mode = 'categorical',\n    target_size = (32,32)\n)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:00:37.640090Z","iopub.execute_input":"2021-11-07T20:00:37.640386Z","iopub.status.idle":"2021-11-07T20:01:10.011681Z","shell.execute_reply.started":"2021-11-07T20:00:37.640348Z","shell.execute_reply":"2021-11-07T20:01:10.010412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TR_STEPS = len(train_loader)\nVA_STEPS = len(valid_loader)\n\nprint(TR_STEPS)\nprint(VA_STEPS)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:01:10.013230Z","iopub.execute_input":"2021-11-07T20:01:10.013482Z","iopub.status.idle":"2021-11-07T20:01:10.020410Z","shell.execute_reply.started":"2021-11-07T20:01:10.013454Z","shell.execute_reply":"2021-11-07T20:01:10.018284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create a simple model","metadata":{}},{"cell_type":"code","source":"cnn = Sequential([\n    Conv2D(16, (3,3), activation = 'relu', padding = 'same', input_shape=(32,32,3)),\n    Conv2D(16, (3,3), activation = 'relu', padding = 'same'),\n    Conv2D(16, (3,3), activation = 'relu', padding = 'same'),\n    MaxPooling2D(2,2),\n    Dropout(0.25),\n    BatchNormalization(),\n\n    Conv2D(32, (3,3), activation = 'relu', padding = 'same'),\n    Conv2D(32, (3,3), activation = 'relu', padding = 'same'),\n    Conv2D(32, (3,3), activation = 'relu', padding = 'same'),\n    MaxPooling2D(2,2),\n    Dropout(0.5),\n    BatchNormalization(),\n\n    Flatten(),\n    \n    Dense(64, activation='relu'),\n    Dropout(0.5),\n    Dense(16, activation='relu'),\n    Dropout(0.5),\n    Dense(8, activation='relu'),\n    Dropout(0.25),\n    BatchNormalization(),\n    Dense(2, activation='softmax')\n])\n\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:01:10.022609Z","iopub.execute_input":"2021-11-07T20:01:10.023314Z","iopub.status.idle":"2021-11-07T20:01:10.524633Z","shell.execute_reply.started":"2021-11-07T20:01:10.023278Z","shell.execute_reply":"2021-11-07T20:01:10.523415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train Network","metadata":{}},{"cell_type":"code","source":"opt = tf.keras.optimizers.Adam(0.001)\ncnn.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy', tf.keras.metrics.AUC()])","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:01:10.525901Z","iopub.execute_input":"2021-11-07T20:01:10.526199Z","iopub.status.idle":"2021-11-07T20:01:10.700283Z","shell.execute_reply.started":"2021-11-07T20:01:10.526166Z","shell.execute_reply":"2021-11-07T20:01:10.699243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Training Run 1","metadata":{}},{"cell_type":"code","source":"%%time \n\nh1 = cnn.fit(\n    x = train_loader, \n    steps_per_epoch = TR_STEPS, \n    epochs = 30,\n    validation_data = valid_loader, \n    validation_steps = VA_STEPS, \n    verbose = 1\n)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:01:10.701782Z","iopub.execute_input":"2021-11-07T20:01:10.702154Z","iopub.status.idle":"2021-11-07T20:18:13.609312Z","shell.execute_reply.started":"2021-11-07T20:01:10.702091Z","shell.execute_reply":"2021-11-07T20:18:13.608287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = h1.history\nprint(history.keys())","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:18:13.611840Z","iopub.execute_input":"2021-11-07T20:18:13.612237Z","iopub.status.idle":"2021-11-07T20:18:13.620877Z","shell.execute_reply.started":"2021-11-07T20:18:13.612188Z","shell.execute_reply":"2021-11-07T20:18:13.619426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epoch_range = range(1, len(history['loss'])+1)\n\nplt.figure(figsize=[14,4])\nplt.subplot(1,3,1)\nplt.plot(epoch_range, history['loss'], label='Training')\nplt.plot(epoch_range, history['val_loss'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Loss'); plt.title('Loss')\nplt.legend()\nplt.subplot(1,3,2)\nplt.plot(epoch_range, history['accuracy'], label='Training')\nplt.plot(epoch_range, history['val_accuracy'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Accuracy'); plt.title('Accuracy')\nplt.legend()\nplt.subplot(1,3,3)\nplt.plot(epoch_range, history['auc'], label='Training')\nplt.plot(epoch_range, history['val_auc'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('AUC'); plt.title('AUC')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:18:13.622422Z","iopub.execute_input":"2021-11-07T20:18:13.622911Z","iopub.status.idle":"2021-11-07T20:18:14.314918Z","shell.execute_reply.started":"2021-11-07T20:18:13.622879Z","shell.execute_reply":"2021-11-07T20:18:14.314007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Training Run 2\ntf.keras.backend.set_value(cnn.optimizer.learning_rate, 0.0001)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:18:14.316427Z","iopub.execute_input":"2021-11-07T20:18:14.316927Z","iopub.status.idle":"2021-11-07T20:18:14.322974Z","shell.execute_reply.started":"2021-11-07T20:18:14.316882Z","shell.execute_reply":"2021-11-07T20:18:14.322066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time \n\nh2 = cnn.fit(\n    x = train_loader, \n    steps_per_epoch = TR_STEPS, \n    epochs = 30,\n    validation_data = valid_loader, \n    validation_steps = VA_STEPS, \n    verbose = 1\n)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:18:14.324701Z","iopub.execute_input":"2021-11-07T20:18:14.325064Z","iopub.status.idle":"2021-11-07T20:33:59.227181Z","shell.execute_reply.started":"2021-11-07T20:18:14.325021Z","shell.execute_reply":"2021-11-07T20:33:59.226271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for k in history.keys():\n    history[k] += h2.history[k]\n\nepoch_range = range(1, len(history['loss'])+1)\n\nplt.figure(figsize=[14,4])\nplt.subplot(1,3,1)\nplt.plot(epoch_range, history['loss'], label='Training')\nplt.plot(epoch_range, history['val_loss'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Loss'); plt.title('Loss')\nplt.legend()\nplt.subplot(1,3,2)\nplt.plot(epoch_range, history['accuracy'], label='Training')\nplt.plot(epoch_range, history['val_accuracy'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Accuracy'); plt.title('Accuracy')\nplt.legend()\nplt.subplot(1,3,3)\nplt.plot(epoch_range, history['auc'], label='Training')\nplt.plot(epoch_range, history['val_auc'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('AUC'); plt.title('AUC')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:33:59.229416Z","iopub.execute_input":"2021-11-07T20:33:59.229781Z","iopub.status.idle":"2021-11-07T20:33:59.721206Z","shell.execute_reply.started":"2021-11-07T20:33:59.229739Z","shell.execute_reply":"2021-11-07T20:33:59.719950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Training Run 3\ntf.keras.backend.set_value(cnn.optimizer.learning_rate, 0.00001)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:37:10.552575Z","iopub.execute_input":"2021-11-07T20:37:10.552884Z","iopub.status.idle":"2021-11-07T20:37:10.558725Z","shell.execute_reply.started":"2021-11-07T20:37:10.552853Z","shell.execute_reply":"2021-11-07T20:37:10.557716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time \n\nh3 = cnn.fit(\n    x = train_loader, \n    steps_per_epoch = TR_STEPS, \n    epochs = 30,\n    validation_data = valid_loader, \n    validation_steps = VA_STEPS, \n    verbose = 1\n)","metadata":{"execution":{"iopub.status.busy":"2021-11-07T20:37:16.327298Z","iopub.execute_input":"2021-11-07T20:37:16.327591Z","iopub.status.idle":"2021-11-07T20:53:03.711117Z","shell.execute_reply.started":"2021-11-07T20:37:16.327564Z","shell.execute_reply":"2021-11-07T20:53:03.710298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for k in history.keys():\n    history[k] += h3.history[k]\n\nepoch_range = range(1, len(history['loss'])+1)\n\nplt.figure(figsize=[14,4])\nplt.subplot(1,3,1)\nplt.plot(epoch_range, history['loss'], label='Training')\nplt.plot(epoch_range, history['val_loss'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Loss'); plt.title('Loss')\nplt.legend()\nplt.subplot(1,3,2)\nplt.plot(epoch_range, history['accuracy'], label='Training')\nplt.plot(epoch_range, history['val_accuracy'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('Accuracy'); plt.title('Accuracy')\nplt.legend()\nplt.subplot(1,3,3)\nplt.plot(epoch_range, history['auc'], label='Training')\nplt.plot(epoch_range, history['val_auc'], label='Validation')\nplt.xlabel('Epoch'); plt.ylabel('AUC'); plt.title('AUC')\nplt.legend()\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-07T21:20:53.813163Z","iopub.execute_input":"2021-11-07T21:20:53.813492Z","iopub.status.idle":"2021-11-07T21:20:54.496459Z","shell.execute_reply.started":"2021-11-07T21:20:53.813460Z","shell.execute_reply":"2021-11-07T21:20:54.495402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Save Model and History","metadata":{}},{"cell_type":"code","source":"cnn.save('cancer_detection_model_v01.h5')\npickle.dump(history, open(f'cancer_detection_history_v01.pkl', 'wb'))","metadata":{"execution":{"iopub.status.busy":"2021-11-07T21:03:08.510229Z","iopub.execute_input":"2021-11-07T21:03:08.510680Z","iopub.status.idle":"2021-11-07T21:03:08.603076Z","shell.execute_reply.started":"2021-11-07T21:03:08.510644Z","shell.execute_reply":"2021-11-07T21:03:08.602319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"### Create image generators for MobileNetV2","metadata":{}},{"cell_type":"markdown","source":"## ","metadata":{}}]}