{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":11848,"databundleVersionId":862157,"sourceType":"competition"},{"sourceId":9106269,"sourceType":"datasetVersion","datasetId":5495936}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Import Packages","metadata":{}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential, load_model\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:19:08.056606Z","iopub.execute_input":"2024-08-05T01:19:08.057010Z","iopub.status.idle":"2024-08-05T01:19:20.324248Z","shell.execute_reply.started":"2024-08-05T01:19:08.056981Z","shell.execute_reply":"2024-08-05T01:19:20.323370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load DataFrame","metadata":{}},{"cell_type":"code","source":"test_directory = '/kaggle/input/histopathologic-cancer-detection/test'\ntest = pd.DataFrame({'id' :os.listdir(test_directory)})","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:19:20.325969Z","iopub.execute_input":"2024-08-05T01:19:20.326493Z","iopub.status.idle":"2024-08-05T01:19:21.546123Z","shell.execute_reply.started":"2024-08-05T01:19:20.326466Z","shell.execute_reply":"2024-08-05T01:19:21.545300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Generator","metadata":{}},{"cell_type":"code","source":"BATCH_SIZE = 256\n\ntest_datagen = ImageDataGenerator(rescale=1/255)\n\ntest_loader = test_datagen.flow_from_dataframe(\n    dataframe = test,\n    directory = test_directory,\n    x_col = 'id', \n    batch_size = BATCH_SIZE, \n    shuffle = False,\n    class_mode = None,\n    target_size = (96,96)\n)","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:19:21.547230Z","iopub.execute_input":"2024-08-05T01:19:21.547527Z","iopub.status.idle":"2024-08-05T01:21:35.613785Z","shell.execute_reply.started":"2024-08-05T01:19:21.547504Z","shell.execute_reply":"2024-08-05T01:21:35.612789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/model12-1/Histopath_model_v12.1.h5'","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:21:35.615177Z","iopub.execute_input":"2024-08-05T01:21:35.615485Z","iopub.status.idle":"2024-08-05T01:21:35.619836Z","shell.execute_reply.started":"2024-08-05T01:21:35.615458Z","shell.execute_reply":"2024-08-05T01:21:35.618928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = load_model(path)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:21:35.622199Z","iopub.execute_input":"2024-08-05T01:21:35.622504Z","iopub.status.idle":"2024-08-05T01:21:37.937701Z","shell.execute_reply.started":"2024-08-05T01:21:35.622480Z","shell.execute_reply":"2024-08-05T01:21:37.936772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Predictions","metadata":{}},{"cell_type":"code","source":"test_probs = model.predict(test_loader, verbose=1)\n","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:21:37.938801Z","iopub.execute_input":"2024-08-05T01:21:37.939058Z","iopub.status.idle":"2024-08-05T01:26:37.355374Z","shell.execute_reply.started":"2024-08-05T01:21:37.939036Z","shell.execute_reply":"2024-08-05T01:26:37.354306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:26:37.356862Z","iopub.execute_input":"2024-08-05T01:26:37.357174Z","iopub.status.idle":"2024-08-05T01:26:37.364083Z","shell.execute_reply.started":"2024-08-05T01:26:37.357147Z","shell.execute_reply":"2024-08-05T01:26:37.363065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred = test_probs[:,0]","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:26:37.365415Z","iopub.execute_input":"2024-08-05T01:26:37.365789Z","iopub.status.idle":"2024-08-05T01:26:37.375109Z","shell.execute_reply.started":"2024-08-05T01:26:37.365758Z","shell.execute_reply":"2024-08-05T01:26:37.374354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/histopathologic-cancer-detection/sample_submission.csv')\nsubmission.label = test_pred","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:26:37.376245Z","iopub.execute_input":"2024-08-05T01:26:37.376574Z","iopub.status.idle":"2024-08-05T01:26:37.484191Z","shell.execute_reply.started":"2024-08-05T01:26:37.376548Z","shell.execute_reply":"2024-08-05T01:26:37.483327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-05T01:26:37.485630Z","iopub.execute_input":"2024-08-05T01:26:37.485943Z","iopub.status.idle":"2024-08-05T01:26:37.696320Z","shell.execute_reply.started":"2024-08-05T01:26:37.485917Z","shell.execute_reply":"2024-08-05T01:26:37.695462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}