{"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":"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-11T17:45:48.678936Z","iopub.execute_input":"2022-04-11T17:45:48.679278Z","iopub.status.idle":"2022-04-11T17:45:55.633622Z","shell.execute_reply.started":"2022-04-11T17:45:48.679187Z","shell.execute_reply":"2022-04-11T17:45:55.632810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:45:55.635531Z","iopub.execute_input":"2022-04-11T17:45:55.635829Z","iopub.status.idle":"2022-04-11T17:45:55.785664Z","shell.execute_reply.started":"2022-04-11T17:45:55.635769Z","shell.execute_reply":"2022-04-11T17:45:55.784678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:45:55.787040Z","iopub.execute_input":"2022-04-11T17:45:55.787243Z","iopub.status.idle":"2022-04-11T17:45:55.804976Z","shell.execute_reply.started":"2022-04-11T17:45:55.787218Z","shell.execute_reply":"2022-04-11T17:45:55.804115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Need .tif extension\n# function to apply the .tif extension\ndef append_ext(fn):\n    return fn+\".tif\"\n\n\ntest['id'] = test['id'].apply(append_ext)\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:45:55.806948Z","iopub.execute_input":"2022-04-11T17:45:55.807174Z","iopub.status.idle":"2022-04-11T17:45:55.847206Z","shell.execute_reply.started":"2022-04-11T17:45:55.807147Z","shell.execute_reply":"2022-04-11T17:45:55.846244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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 ='../input/histopathologic-cancer-detection/test',\n    x_col = 'id',\n    batch_size = BATCH_SIZE,\n    seed = 1,\n    shuffle = False,\n    class_mode = None,\n    target_size = (32,32)\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:45:55.848746Z","iopub.execute_input":"2022-04-11T17:45:55.849019Z","iopub.status.idle":"2022-04-11T17:49:31.495263Z","shell.execute_reply.started":"2022-04-11T17:45:55.848989Z","shell.execute_reply":"2022-04-11T17:49:31.494230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnn = keras.models.load_model('../input/cancer-detection/cancer_model16.h5')\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:49:31.496665Z","iopub.execute_input":"2022-04-11T17:49:31.496925Z","iopub.status.idle":"2022-04-11T17:49:32.162351Z","shell.execute_reply.started":"2022-04-11T17:49:31.496895Z","shell.execute_reply":"2022-04-11T17:49:32.161534Z"},"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-04-11T17:49:32.163967Z","iopub.execute_input":"2022-04-11T17:49:32.164275Z","iopub.status.idle":"2022-04-11T17:57:15.086040Z","shell.execute_reply.started":"2022-04-11T17:49:32.164241Z","shell.execute_reply":"2022-04-11T17:57:15.085211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_probs[:10,].round(2))","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:57:15.087531Z","iopub.execute_input":"2022-04-11T17:57:15.088241Z","iopub.status.idle":"2022-04-11T17:57:15.094825Z","shell.execute_reply.started":"2022-04-11T17:57:15.088193Z","shell.execute_reply":"2022-04-11T17:57:15.094069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('../input/histopathologic-cancer-detection/sample_submission.csv')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:57:15.096077Z","iopub.execute_input":"2022-04-11T17:57:15.096712Z","iopub.status.idle":"2022-04-11T17:57:15.202984Z","shell.execute_reply.started":"2022-04-11T17:57:15.096675Z","shell.execute_reply":"2022-04-11T17:57:15.201858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.label = test_probs[:,1]\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T17:57:15.205655Z","iopub.execute_input":"2022-04-11T17:57:15.206028Z","iopub.status.idle":"2022-04-11T17:57:15.225896Z","shell.execute_reply.started":"2022-04-11T17:57:15.205991Z","shell.execute_reply":"2022-04-11T17:57:15.224680Z"},"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-04-11T17:57:15.227618Z","iopub.execute_input":"2022-04-11T17:57:15.228679Z","iopub.status.idle":"2022-04-11T17:57:15.505144Z","shell.execute_reply.started":"2022-04-11T17:57:15.228626Z","shell.execute_reply":"2022-04-11T17:57:15.504134Z"},"trusted":true},"execution_count":null,"outputs":[]}]}