{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":11848,"databundleVersionId":862157,"sourceType":"competition"}],"dockerImageVersionId":30587,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"#import packages\nimport os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nfrom sklearn.model_selection import train_test_split\nimport pickle\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import *\nimport keras_tuner as kt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-18T03:32:09.3146Z","iopub.execute_input":"2023-11-18T03:32:09.315065Z","iopub.status.idle":"2023-11-18T03:32:14.06511Z","shell.execute_reply.started":"2023-11-18T03:32:09.315025Z","shell.execute_reply":"2023-11-18T03:32:14.063676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hcd = pd.read_csv('/kaggle/input/histopathologic-cancer-detection/train_labels.csv')\nprint(hcd.shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.067436Z","iopub.execute_input":"2023-11-18T03:32:14.068059Z","iopub.status.idle":"2023-11-18T03:32:14.357779Z","shell.execute_reply.started":"2023-11-18T03:32:14.068027Z","shell.execute_reply":"2023-11-18T03:32:14.356612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display the first few rows of the dataframe.\nhcd.head() ","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.359266Z","iopub.execute_input":"2023-11-18T03:32:14.359646Z","iopub.status.idle":"2023-11-18T03:32:14.376111Z","shell.execute_reply.started":"2023-11-18T03:32:14.359613Z","shell.execute_reply":"2023-11-18T03:32:14.374522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#label distrobution\n(hcd.label.value_counts() / len(hcd)).to_frame()","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.378153Z","iopub.execute_input":"2023-11-18T03:32:14.378549Z","iopub.status.idle":"2023-11-18T03:32:14.394455Z","shell.execute_reply.started":"2023-11-18T03:32:14.378518Z","shell.execute_reply":"2023-11-18T03:32:14.392775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Adding a variable for the image directory\nimg_dir = '/kaggle/input/histopathologic-cancer-detection/train'","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.398126Z","iopub.execute_input":"2023-11-18T03:32:14.398627Z","iopub.status.idle":"2023-11-18T03:32:14.406098Z","shell.execute_reply.started":"2023-11-18T03:32:14.398582Z","shell.execute_reply":"2023-11-18T03:32:14.404648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 32\nimg_height = 180\nimg_width = 180","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.408307Z","iopub.execute_input":"2023-11-18T03:32:14.409594Z","iopub.status.idle":"2023-11-18T03:32:14.419845Z","shell.execute_reply.started":"2023-11-18T03:32:14.40954Z","shell.execute_reply":"2023-11-18T03:32:14.417873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#using data generators \ntrain_df, valid_df = train_test_split(hcd, test_size=0.2, random_state=39, stratify=hcd.label)\n\nprint(train_df.shape)\nprint(valid_df.shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.422087Z","iopub.execute_input":"2023-11-18T03:32:14.422942Z","iopub.status.idle":"2023-11-18T03:32:14.604145Z","shell.execute_reply.started":"2023-11-18T03:32:14.422891Z","shell.execute_reply":"2023-11-18T03:32:14.602956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(rescale=1/255)\nvalid_datagen = ImageDataGenerator(rescale=1/255)","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.605718Z","iopub.execute_input":"2023-11-18T03:32:14.606096Z","iopub.status.idle":"2023-11-18T03:32:14.612404Z","shell.execute_reply.started":"2023-11-18T03:32:14.606064Z","shell.execute_reply":"2023-11-18T03:32:14.610814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['id'] = train_df['id'] + '.tif'\nvalid_df['id'] = valid_df['id'] + '.tif'","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:32:14.614288Z","iopub.execute_input":"2023-11-18T03:32:14.614666Z","iopub.status.idle":"2023-11-18T03:32:14.713822Z","shell.execute_reply.started":"2023-11-18T03:32:14.614634Z","shell.execute_reply":"2023-11-18T03:32:14.712513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-11-18T03:35:13.30136Z","iopub.execute_input":"2023-11-18T03:35:13.301888Z","iopub.status.idle":"2023-11-18T03:35:15.758008Z","shell.execute_reply.started":"2023-11-18T03:35:13.301849Z","shell.execute_reply":"2023-11-18T03:35:15.755914Z"},"trusted":true},"execution_count":null,"outputs":[]}]}