{"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":"none","dataSources":[{"sourceId":11848,"databundleVersionId":862157,"sourceType":"competition"},{"sourceId":9054168,"sourceType":"datasetVersion","datasetId":5459435}],"dockerImageVersionId":30747,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\nfrom tensorflow import keras\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:21:09.429721Z","iopub.execute_input":"2024-07-29T04:21:09.430152Z","iopub.status.idle":"2024-07-29T04:21:22.027236Z","shell.execute_reply.started":"2024-07-29T04:21:09.430121Z","shell.execute_reply":"2024-07-29T04:21:22.026469Z"},"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-07-29T04:21:22.029508Z","iopub.execute_input":"2024-07-29T04:21:22.030169Z","iopub.status.idle":"2024-07-29T04:21:24.505851Z","shell.execute_reply.started":"2024-07-29T04:21:22.030130Z","shell.execute_reply":"2024-07-29T04:21:24.505040Z"},"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 = (64,64)\n)","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:21:24.506961Z","iopub.execute_input":"2024-07-29T04:21:24.507255Z","iopub.status.idle":"2024-07-29T04:24:14.199658Z","shell.execute_reply.started":"2024-07-29T04:21:24.507229Z","shell.execute_reply":"2024-07-29T04:24:14.198893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnn = keras.models.load_model('/kaggle/input/modelv10/Histopath_model_v10.h5')\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:26:43.800998Z","iopub.execute_input":"2024-07-29T04:26:43.801359Z","iopub.status.idle":"2024-07-29T04:26:45.716131Z","shell.execute_reply.started":"2024-07-29T04:26:43.801331Z","shell.execute_reply":"2024-07-29T04:26:45.714877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Predictions","metadata":{}},{"cell_type":"code","source":"test_probs = base_model.predict(test_loader, verbose=1)","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:24:15.271232Z","iopub.status.idle":"2024-07-29T04:24:15.271615Z","shell.execute_reply.started":"2024-07-29T04:24:15.271416Z","shell.execute_reply":"2024-07-29T04:24:15.271432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:24:15.273129Z","iopub.status.idle":"2024-07-29T04:24:15.273446Z","shell.execute_reply.started":"2024-07-29T04:24:15.273284Z","shell.execute_reply":"2024-07-29T04:24:15.273296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred = test_probs[:,1]","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:24:15.274902Z","iopub.status.idle":"2024-07-29T04:24:15.275203Z","shell.execute_reply.started":"2024-07-29T04:24:15.275055Z","shell.execute_reply":"2024-07-29T04:24:15.275068Z"},"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\nsubmisson.to_string(index=False)","metadata":{"execution":{"iopub.status.busy":"2024-07-29T04:24:15.276146Z","iopub.status.idle":"2024-07-29T04:24:15.276493Z","shell.execute_reply.started":"2024-07-29T04:24:15.276305Z","shell.execute_reply":"2024-07-29T04:24:15.276325Z"},"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-07-29T04:24:15.278536Z","iopub.status.idle":"2024-07-29T04:24:15.278872Z","shell.execute_reply.started":"2024-07-29T04:24:15.278715Z","shell.execute_reply":"2024-07-29T04:24:15.278729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}