{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Import Statements","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nimport matplotlib.image as mpimg\n\nfrom sklearn.model_selection import train_test_split\n\nimport pickle\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import *\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\n\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-19T00:35:56.154053Z","iopub.execute_input":"2021-11-19T00:35:56.154395Z","iopub.status.idle":"2021-11-19T00:36:02.016974Z","shell.execute_reply.started":"2021-11-19T00:35:56.154308Z","shell.execute_reply":"2021-11-19T00:36:02.016214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\nprint('Test Set Size:', test.shape)\n\n# test = test.iloc[:100,]\n# print('Test Set Size:', test.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:02.022078Z","iopub.execute_input":"2021-11-19T00:36:02.02418Z","iopub.status.idle":"2021-11-19T00:36:02.201532Z","shell.execute_reply.started":"2021-11-19T00:36:02.02414Z","shell.execute_reply":"2021-11-19T00:36:02.200802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:02.205367Z","iopub.execute_input":"2021-11-19T00:36:02.207213Z","iopub.status.idle":"2021-11-19T00:36:02.231684Z","shell.execute_reply.started":"2021-11-19T00:36:02.207173Z","shell.execute_reply":"2021-11-19T00:36:02.230256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['id'] = test['id'].apply(lambda x: f'{x}.tif')\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:02.236269Z","iopub.execute_input":"2021-11-19T00:36:02.236468Z","iopub.status.idle":"2021-11-19T00:36:02.271089Z","shell.execute_reply.started":"2021-11-19T00:36:02.236443Z","shell.execute_reply":"2021-11-19T00:36:02.270392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Generator","metadata":{}},{"cell_type":"code","source":"BATCH_SIZE = 64\ntest_path = \"../input/histopathologic-cancer-detection/test\"\nprint('Test Images:', len(os.listdir(test_path)))\n\ntest_datagen = ImageDataGenerator(rescale=1/255)\n\ntest_loader = test_datagen.flow_from_dataframe(\n    dataframe = test,\n    directory = test_path,\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":"2021-11-19T00:36:02.272184Z","iopub.execute_input":"2021-11-19T00:36:02.272436Z","iopub.status.idle":"2021-11-19T00:36:32.19686Z","shell.execute_reply.started":"2021-11-19T00:36:02.2724Z","shell.execute_reply":"2021-11-19T00:36:32.194811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnn = keras.models.load_model('../input/cancer-models/cancer_model_v01_version10.h5')\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.197664Z","iopub.status.idle":"2021-11-19T00:36:32.197949Z","shell.execute_reply.started":"2021-11-19T00:36:32.197799Z","shell.execute_reply":"2021-11-19T00:36:32.197818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Predictions","metadata":{}},{"cell_type":"code","source":"test_probs = cnn.predict(test_loader)\nprint(test_probs.shape)","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.199397Z","iopub.status.idle":"2021-11-19T00:36:32.200201Z","shell.execute_reply.started":"2021-11-19T00:36:32.199956Z","shell.execute_reply":"2021-11-19T00:36:32.199982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_probs[:10,].round(2))","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.20142Z","iopub.status.idle":"2021-11-19T00:36:32.202242Z","shell.execute_reply.started":"2021-11-19T00:36:32.201997Z","shell.execute_reply":"2021-11-19T00:36:32.202023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Update submission","metadata":{}},{"cell_type":"code","source":"submission = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.203499Z","iopub.status.idle":"2021-11-19T00:36:32.204229Z","shell.execute_reply.started":"2021-11-19T00:36:32.203991Z","shell.execute_reply":"2021-11-19T00:36:32.204015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.label = test_probs[:,1]\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.20575Z","iopub.status.idle":"2021-11-19T00:36:32.206153Z","shell.execute_reply.started":"2021-11-19T00:36:32.205933Z","shell.execute_reply":"2021-11-19T00:36:32.205955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', header=True, index=False)","metadata":{"execution":{"iopub.status.busy":"2021-11-19T00:36:32.207661Z","iopub.status.idle":"2021-11-19T00:36:32.208347Z","shell.execute_reply.started":"2021-11-19T00:36:32.2081Z","shell.execute_reply":"2021-11-19T00:36:32.208126Z"},"trusted":true},"execution_count":null,"outputs":[]}]}