{"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\nimport matplotlib.image as mpimg\n\ntest_path = '/kaggle/input/histopathologic-cancer-detection/test/'","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-17T21:06:36.137961Z","iopub.execute_input":"2021-11-17T21:06:36.138912Z","iopub.status.idle":"2021-11-17T21:06:42.161594Z","shell.execute_reply.started":"2021-11-17T21:06:36.138818Z","shell.execute_reply":"2021-11-17T21:06:42.160442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv(f'../input/histopathologic-cancer-detection/sample_submission.csv', dtype=str)\n\nprint('Test Set Size:', test.shape)\n\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:06:49.295012Z","iopub.execute_input":"2021-11-17T21:06:49.295647Z","iopub.status.idle":"2021-11-17T21:06:49.490408Z","shell.execute_reply.started":"2021-11-17T21:06:49.295612Z","shell.execute_reply":"2021-11-17T21:06:49.48933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['path'] = test.id + '.tif'","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:06:52.55331Z","iopub.execute_input":"2021-11-17T21:06:52.553724Z","iopub.status.idle":"2021-11-17T21:06:52.574421Z","shell.execute_reply.started":"2021-11-17T21:06:52.55368Z","shell.execute_reply":"2021-11-17T21:06:52.573479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen = ImageDataGenerator(rescale=1/255)","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:06:55.962336Z","iopub.execute_input":"2021-11-17T21:06:55.962666Z","iopub.status.idle":"2021-11-17T21:06:55.968526Z","shell.execute_reply.started":"2021-11-17T21:06:55.962633Z","shell.execute_reply":"2021-11-17T21:06:55.967022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 64\n\ntest_loader = test_datagen.flow_from_dataframe(\n    dataframe = test,\n    directory = test_path,\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":"2021-11-17T21:07:03.499419Z","iopub.execute_input":"2021-11-17T21:07:03.50046Z","iopub.status.idle":"2021-11-17T21:09:48.602503Z","shell.execute_reply.started":"2021-11-17T21:07:03.5004Z","shell.execute_reply":"2021-11-17T21:09:48.601309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnn = keras.models.load_model('../input/modelsaug3/JW2_cancer_model_v01.h5')\ncnn.summary()","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:10:27.318619Z","iopub.execute_input":"2021-11-17T21:10:27.318902Z","iopub.status.idle":"2021-11-17T21:10:30.639866Z","shell.execute_reply.started":"2021-11-17T21:10:27.318867Z","shell.execute_reply":"2021-11-17T21:10:30.638707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_probs = cnn.predict(test_loader)","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:10:34.771275Z","iopub.execute_input":"2021-11-17T21:10:34.771575Z","iopub.status.idle":"2021-11-17T21:17:28.36242Z","shell.execute_reply.started":"2021-11-17T21:10:34.771544Z","shell.execute_reply":"2021-11-17T21:17:28.36127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_probs[:10,].round(2))","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:17:33.483963Z","iopub.execute_input":"2021-11-17T21:17:33.484374Z","iopub.status.idle":"2021-11-17T21:17:33.491362Z","shell.execute_reply.started":"2021-11-17T21:17:33.484327Z","shell.execute_reply":"2021-11-17T21:17:33.489951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_preds = np.argmax(test_probs, axis=1)\n#print(test_preds[:10])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(f'../input/histopathologic-cancer-detection/sample_submission.csv', dtype=str)\nsubmission.label = test_probs[:,1]\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-17T21:17:45.561233Z","iopub.execute_input":"2021-11-17T21:17:45.561519Z","iopub.status.idle":"2021-11-17T21:17:45.626155Z","shell.execute_reply.started":"2021-11-17T21:17:45.56149Z","shell.execute_reply":"2021-11-17T21:17:45.62493Z"},"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-17T21:17:49.469103Z","iopub.execute_input":"2021-11-17T21:17:49.469977Z","iopub.status.idle":"2021-11-17T21:17:49.776421Z","shell.execute_reply.started":"2021-11-17T21:17:49.469938Z","shell.execute_reply":"2021-11-17T21:17:49.775335Z"},"trusted":true},"execution_count":null,"outputs":[]}]}