{"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":"# HCD Submission","metadata":{}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport zipfile\nfrom tensorflow import keras\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.141748Z","iopub.execute_input":"2022-03-14T18:44:35.145458Z","iopub.status.idle":"2022-03-14T18:44:35.153765Z","shell.execute_reply.started":"2022-03-14T18:44:35.145401Z","shell.execute_reply":"2022-03-14T18:44:35.152610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Dataframe","metadata":{}},{"cell_type":"code","source":"test = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\n\nprint('Test Set Size:', test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.156819Z","iopub.execute_input":"2022-03-14T18:44:35.157781Z","iopub.status.idle":"2022-03-14T18:44:35.258709Z","shell.execute_reply.started":"2022-03-14T18:44:35.157731Z","shell.execute_reply":"2022-03-14T18:44:35.256199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['filename'] = test.id + '.tif'","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.264174Z","iopub.execute_input":"2022-03-14T18:44:35.264749Z","iopub.status.idle":"2022-03-14T18:44:35.290633Z","shell.execute_reply.started":"2022-03-14T18:44:35.264702Z","shell.execute_reply":"2022-03-14T18:44:35.289417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.292445Z","iopub.execute_input":"2022-03-14T18:44:35.293010Z","iopub.status.idle":"2022-03-14T18:44:35.308743Z","shell.execute_reply.started":"2022-03-14T18:44:35.292966Z","shell.execute_reply":"2022-03-14T18:44:35.307859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_path = \"../input/histopathologic-cancer-detection/test\"\nprint('Test Images:', len(os.listdir(test_path)))","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.311656Z","iopub.execute_input":"2022-03-14T18:44:35.312288Z","iopub.status.idle":"2022-03-14T18:44:35.374487Z","shell.execute_reply.started":"2022-03-14T18:44:35.312243Z","shell.execute_reply":"2022-03-14T18:44:35.372518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Generator","metadata":{}},{"cell_type":"code","source":"BATCH_SIZE = 64\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 = 'filename',\n    batch_size = BATCH_SIZE,\n    shuffle = False,\n    class_mode = None,\n    target_size = (96,96)\n)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:35.376194Z","iopub.execute_input":"2022-03-14T18:44:35.376716Z","iopub.status.idle":"2022-03-14T18:44:51.657405Z","shell.execute_reply.started":"2022-03-14T18:44:35.376669Z","shell.execute_reply":"2022-03-14T18:44:51.656360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Model","metadata":{}},{"cell_type":"code","source":"cnn = keras.models.load_model('../input/hcd601/HCDv01.h5')\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:51.658863Z","iopub.execute_input":"2022-03-14T18:44:51.659954Z","iopub.status.idle":"2022-03-14T18:44:52.141091Z","shell.execute_reply.started":"2022-03-14T18:44:51.659905Z","shell.execute_reply":"2022-03-14T18:44:52.140175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs = cnn.predict(test_loader)\nprint(test_probs.shape)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:44:52.143018Z","iopub.execute_input":"2022-03-14T18:44:52.143385Z","iopub.status.idle":"2022-03-14T18:46:20.899372Z","shell.execute_reply.started":"2022-03-14T18:44:52.143339Z","shell.execute_reply":"2022-03-14T18:46:20.898323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(test_loader))\n","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:46:20.901025Z","iopub.execute_input":"2022-03-14T18:46:20.901478Z","iopub.status.idle":"2022-03-14T18:46:20.911010Z","shell.execute_reply.started":"2022-03-14T18:46:20.901431Z","shell.execute_reply":"2022-03-14T18:46:20.909519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_probs[:10,].round(2))\n","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:46:20.913142Z","iopub.execute_input":"2022-03-14T18:46:20.913495Z","iopub.status.idle":"2022-03-14T18:46:20.922003Z","shell.execute_reply.started":"2022-03-14T18:46:20.913447Z","shell.execute_reply":"2022-03-14T18:46:20.920743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_pred = np.argmax(test_probs, axis=1)\nprint(test_pred[:10])","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:46:20.926515Z","iopub.execute_input":"2022-03-14T18:46:20.927595Z","iopub.status.idle":"2022-03-14T18:46:20.937636Z","shell.execute_reply.started":"2022-03-14T18:46:20.927550Z","shell.execute_reply":"2022-03-14T18:46:20.936385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Prepare Submission","metadata":{}},{"cell_type":"code","source":"submission = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:46:20.939462Z","iopub.execute_input":"2022-03-14T18:46:20.939999Z","iopub.status.idle":"2022-03-14T18:46:21.003287Z","shell.execute_reply.started":"2022-03-14T18:46:20.939952Z","shell.execute_reply":"2022-03-14T18:46:21.002235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.label = test_probs[:,1]\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:47:17.417172Z","iopub.execute_input":"2022-03-14T18:47:17.417489Z","iopub.status.idle":"2022-03-14T18:47:17.430403Z","shell.execute_reply.started":"2022-03-14T18:47:17.417456Z","shell.execute_reply":"2022-03-14T18:47:17.429396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', header=True, index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-14T18:46:21.021378Z","iopub.execute_input":"2022-03-14T18:46:21.022035Z","iopub.status.idle":"2022-03-14T18:46:21.192750Z","shell.execute_reply.started":"2022-03-14T18:46:21.021984Z","shell.execute_reply":"2022-03-14T18:46:21.191651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}