{"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"},{"sourceId":7007089,"sourceType":"datasetVersion","datasetId":4028277},{"sourceId":7007234,"sourceType":"datasetVersion","datasetId":4028376},{"sourceId":7093730,"sourceType":"datasetVersion","datasetId":4088171},{"sourceId":7164328,"sourceType":"datasetVersion","datasetId":4138425},{"sourceId":7170579,"sourceType":"datasetVersion","datasetId":4142933}],"dockerImageVersionId":30588,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom tensorflow import keras\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nimport matplotlib.image as mpimg\nimport pickle\nfrom keras.models import load_model","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-10T19:04:40.509921Z","iopub.execute_input":"2023-12-10T19:04:40.510325Z","iopub.status.idle":"2023-12-10T19:04:53.891887Z","shell.execute_reply.started":"2023-12-10T19:04:40.510295Z","shell.execute_reply":"2023-12-10T19:04:53.890695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = '/kaggle/input/histopathologic-cancer-detection/test/'\ndf = pd.read_csv(f'../input/histopathologic-cancer-detection/sample_submission.csv', dtype=str)\n\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:53.894059Z","iopub.execute_input":"2023-12-10T19:04:53.894699Z","iopub.status.idle":"2023-12-10T19:04:54.096979Z","shell.execute_reply.started":"2023-12-10T19:04:53.894662Z","shell.execute_reply":"2023-12-10T19:04:54.096109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:54.098154Z","iopub.execute_input":"2023-12-10T19:04:54.099162Z","iopub.status.idle":"2023-12-10T19:04:54.118793Z","shell.execute_reply.started":"2023-12-10T19:04:54.099128Z","shell.execute_reply":"2023-12-10T19:04:54.117903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['path'] = df.id + '.tif'","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:54.120158Z","iopub.execute_input":"2023-12-10T19:04:54.121237Z","iopub.status.idle":"2023-12-10T19:04:54.137477Z","shell.execute_reply.started":"2023-12-10T19:04:54.121198Z","shell.execute_reply":"2023-12-10T19:04:54.136186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df['path'].head())","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:54.140561Z","iopub.execute_input":"2023-12-10T19:04:54.140982Z","iopub.status.idle":"2023-12-10T19:04:54.150549Z","shell.execute_reply.started":"2023-12-10T19:04:54.140949Z","shell.execute_reply":"2023-12-10T19:04:54.149403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen = ImageDataGenerator(rescale=1/255)","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:54.152476Z","iopub.execute_input":"2023-12-10T19:04:54.152912Z","iopub.status.idle":"2023-12-10T19:04:54.160332Z","shell.execute_reply.started":"2023-12-10T19:04:54.152813Z","shell.execute_reply":"2023-12-10T19:04:54.159092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 64\n\ntest_loader = test_datagen.flow_from_dataframe(\n    dataframe = df,\n    directory = test,\n    x_col = 'path',\n    batch_size = BATCH_SIZE,\n    shuffle = False,\n    class_mode = None,\n    target_size = (96,96)\n)","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:04:54.161738Z","iopub.execute_input":"2023-12-10T19:04:54.162144Z","iopub.status.idle":"2023-12-10T19:07:40.479422Z","shell.execute_reply.started":"2023-12-10T19:04:54.162115Z","shell.execute_reply":"2023-12-10T19:07:40.478480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check if the file exists\nos.path.exists('/kaggle/input/hcd-tf-x')","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:07:40.480652Z","iopub.execute_input":"2023-12-10T19:07:40.481528Z","iopub.status.idle":"2023-12-10T19:07:40.488278Z","shell.execute_reply.started":"2023-12-10T19:07:40.481495Z","shell.execute_reply":"2023-12-10T19:07:40.487301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kt_model = load_model('/kaggle/input/hcd-tests/HCD_SB_6_3_Model (1).h5')\n\n# Load the history\nwith open('/kaggle/input/hcd-tests/HCD_SB_6_3_Model_history (1).pkl', 'rb') as file:\n    loaded_history = pickle.load(file)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:07:40.489684Z","iopub.execute_input":"2023-12-10T19:07:40.490010Z","iopub.status.idle":"2023-12-10T19:07:40.901143Z","shell.execute_reply.started":"2023-12-10T19:07:40.489983Z","shell.execute_reply":"2023-12-10T19:07:40.900044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs = kt_model.predict(test_loader)","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:07:40.902435Z","iopub.execute_input":"2023-12-10T19:07:40.902777Z","iopub.status.idle":"2023-12-10T19:16:03.642451Z","shell.execute_reply.started":"2023-12-10T19:07:40.902740Z","shell.execute_reply":"2023-12-10T19:16:03.641252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(\"/kaggle/input/histopathologic-cancer-detection/sample_submission.csv\")\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:16:03.643790Z","iopub.execute_input":"2023-12-10T19:16:03.644178Z","iopub.status.idle":"2023-12-10T19:16:03.705666Z","shell.execute_reply.started":"2023-12-10T19:16:03.644145Z","shell.execute_reply":"2023-12-10T19:16:03.704629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.label = test_probs\nsubmission.head() ","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:16:03.706951Z","iopub.execute_input":"2023-12-10T19:16:03.707264Z","iopub.status.idle":"2023-12-10T19:16:03.717732Z","shell.execute_reply.started":"2023-12-10T19:16:03.707237Z","shell.execute_reply":"2023-12-10T19:16:03.716670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', header=True, index=False)","metadata":{"execution":{"iopub.status.busy":"2023-12-10T19:16:03.719086Z","iopub.execute_input":"2023-12-10T19:16:03.719418Z","iopub.status.idle":"2023-12-10T19:16:03.911546Z","shell.execute_reply.started":"2023-12-10T19:16:03.719392Z","shell.execute_reply":"2023-12-10T19:16:03.910405Z"},"trusted":true},"execution_count":null,"outputs":[]}]}