{"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":9138313,"sourceType":"datasetVersion","datasetId":5518820}],"dockerImageVersionId":30747,"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-09T06:08:46.908609Z","iopub.execute_input":"2024-08-09T06:08:46.909816Z","iopub.status.idle":"2024-08-09T06:09:00.338229Z","shell.execute_reply.started":"2024-08-09T06:08:46.909777Z","shell.execute_reply":"2024-08-09T06:09:00.337376Z"},"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-09T06:09:00.340086Z","iopub.execute_input":"2024-08-09T06:09:00.340751Z","iopub.status.idle":"2024-08-09T06:09:05.300226Z","shell.execute_reply.started":"2024-08-09T06:09:00.340724Z","shell.execute_reply":"2024-08-09T06:09:05.299399Z"},"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-09T06:09:05.301374Z","iopub.execute_input":"2024-08-09T06:09:05.301683Z","iopub.status.idle":"2024-08-09T06:12:01.524242Z","shell.execute_reply.started":"2024-08-09T06:09:05.301657Z","shell.execute_reply":"2024-08-09T06:12:01.523303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/week6v13/Histopath_model_v13.h5'","metadata":{"execution":{"iopub.status.busy":"2024-08-09T06:12:01.525445Z","iopub.execute_input":"2024-08-09T06:12:01.525744Z","iopub.status.idle":"2024-08-09T06:12:01.530495Z","shell.execute_reply.started":"2024-08-09T06:12:01.525718Z","shell.execute_reply":"2024-08-09T06:12:01.529497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = load_model(path)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-08-09T06:12:01.533379Z","iopub.execute_input":"2024-08-09T06:12:01.534074Z","iopub.status.idle":"2024-08-09T06:12:03.722786Z","shell.execute_reply.started":"2024-08-09T06:12:01.534049Z","shell.execute_reply":"2024-08-09T06:12:03.721823Z"},"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-09T06:12:03.724133Z","iopub.execute_input":"2024-08-09T06:12:03.724510Z","iopub.status.idle":"2024-08-09T06:19:11.670935Z","shell.execute_reply.started":"2024-08-09T06:12:03.724467Z","shell.execute_reply":"2024-08-09T06:19:11.669831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs","metadata":{"execution":{"iopub.status.busy":"2024-08-09T06:19:11.672416Z","iopub.execute_input":"2024-08-09T06:19:11.672726Z","iopub.status.idle":"2024-08-09T06:19:11.679753Z","shell.execute_reply.started":"2024-08-09T06:19:11.672699Z","shell.execute_reply":"2024-08-09T06:19:11.678696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred = test_probs[:,0]","metadata":{"execution":{"iopub.status.busy":"2024-08-09T06:19:11.680978Z","iopub.execute_input":"2024-08-09T06:19:11.681568Z","iopub.status.idle":"2024-08-09T06:19:11.690527Z","shell.execute_reply.started":"2024-08-09T06:19:11.681540Z","shell.execute_reply":"2024-08-09T06:19:11.689566Z"},"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-09T06:19:11.691759Z","iopub.execute_input":"2024-08-09T06:19:11.694766Z","iopub.status.idle":"2024-08-09T06:19:11.786948Z","shell.execute_reply.started":"2024-08-09T06:19:11.694732Z","shell.execute_reply":"2024-08-09T06:19:11.785937Z"},"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-09T06:19:11.788195Z","iopub.execute_input":"2024-08-09T06:19:11.788527Z","iopub.status.idle":"2024-08-09T06:19:11.994427Z","shell.execute_reply.started":"2024-08-09T06:19:11.788499Z","shell.execute_reply":"2024-08-09T06:19:11.993613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}