{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":11848,"databundleVersionId":862157,"sourceType":"competition"},{"sourceId":10071477,"sourceType":"datasetVersion","datasetId":6207751},{"sourceId":10073114,"sourceType":"datasetVersion","datasetId":6208906},{"sourceId":10079977,"sourceType":"datasetVersion","datasetId":6214068},{"sourceId":10164301,"sourceType":"datasetVersion","datasetId":6276701}],"dockerImageVersionId":30787,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n\nfrom tensorflow import keras\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:54:08.328263Z","iopub.execute_input":"2024-12-11T01:54:08.328959Z","iopub.status.idle":"2024-12-11T01:54:21.057071Z","shell.execute_reply.started":"2024-12-11T01:54:08.328927Z","shell.execute_reply":"2024-12-11T01:54:21.056383Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/histopathologic-cancer-detection/sample_submission.csv')\nprint(test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:54:21.058660Z","iopub.execute_input":"2024-12-11T01:54:21.059131Z","iopub.status.idle":"2024-12-11T01:54:21.178989Z","shell.execute_reply.started":"2024-12-11T01:54:21.059103Z","shell.execute_reply":"2024-12-11T01:54:21.178135Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:54:21.180217Z","iopub.execute_input":"2024-12-11T01:54:21.180851Z","iopub.status.idle":"2024-12-11T01:54:21.197416Z","shell.execute_reply.started":"2024-12-11T01:54:21.180812Z","shell.execute_reply":"2024-12-11T01:54:21.196537Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['fileName'] = test['id'] + '.tif'","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:54:21.198524Z","iopub.execute_input":"2024-12-11T01:54:21.198751Z","iopub.status.idle":"2024-12-11T01:54:21.211095Z","shell.execute_reply.started":"2024-12-11T01:54:21.198729Z","shell.execute_reply":"2024-12-11T01:54:21.210133Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_datagen = ImageDataGenerator(rescale=1/255)\nBATCH_SIZE = 64\nIMG_WIDTH = 96\nIMG_HEIGHT = 96\ntest_path = '/kaggle/input/histopathologic-cancer-detection/test'\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    seed = 1,\n    shuffle = False,\n    class_mode = None,\n    target_size = (IMG_WIDTH, IMG_HEIGHT)\n)","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:54:21.213008Z","iopub.execute_input":"2024-12-11T01:54:21.213313Z","iopub.status.idle":"2024-12-11T01:56:18.957704Z","shell.execute_reply.started":"2024-12-11T01:54:21.213286Z","shell.execute_reply":"2024-12-11T01:56:18.957027Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"modelLocation = '/kaggle/input/model-v12/AM_histopathologic-cancer-detection_v12.h5'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-11T01:56:18.958731Z","iopub.execute_input":"2024-12-11T01:56:18.959046Z","iopub.status.idle":"2024-12-11T01:56:18.963151Z","shell.execute_reply.started":"2024-12-11T01:56:18.959019Z","shell.execute_reply":"2024-12-11T01:56:18.962198Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cnn_model = keras.models.load_model(modelLocation)\ncnn_model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:56:18.964306Z","iopub.execute_input":"2024-12-11T01:56:18.964655Z","iopub.status.idle":"2024-12-11T01:56:23.115461Z","shell.execute_reply.started":"2024-12-11T01:56:18.964595Z","shell.execute_reply":"2024-12-11T01:56:23.114634Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred = cnn_model.predict(test_loader)\nprint(test_pred.shape)","metadata":{"execution":{"iopub.status.busy":"2024-12-11T01:56:23.116508Z","iopub.execute_input":"2024-12-11T01:56:23.116775Z","iopub.status.idle":"2024-12-11T02:01:17.127115Z","shell.execute_reply.started":"2024-12-11T01:56:23.116750Z","shell.execute_reply":"2024-12-11T02:01:17.126195Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(test_pred[:10,].round(2))","metadata":{"execution":{"iopub.status.busy":"2024-12-11T02:01:17.128451Z","iopub.execute_input":"2024-12-11T02:01:17.128840Z","iopub.status.idle":"2024-12-11T02:01:17.134405Z","shell.execute_reply.started":"2024-12-11T02:01:17.128800Z","shell.execute_reply":"2024-12-11T02:01:17.133547Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred = np.argmax(test_pred, axis=1)\nprint(test_pred[:10,])","metadata":{"execution":{"iopub.status.busy":"2024-12-11T02:01:17.135554Z","iopub.execute_input":"2024-12-11T02:01:17.135916Z","iopub.status.idle":"2024-12-11T02:01:17.146421Z","shell.execute_reply.started":"2024-12-11T02:01:17.135874Z","shell.execute_reply":"2024-12-11T02:01:17.145515Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/histopathologic-cancer-detection/sample_submission.csv')\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-11T02:01:17.147422Z","iopub.execute_input":"2024-12-11T02:01:17.147672Z","iopub.status.idle":"2024-12-11T02:01:17.208636Z","shell.execute_reply.started":"2024-12-11T02:01:17.147648Z","shell.execute_reply":"2024-12-11T02:01:17.207773Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.label = test_pred\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-11T02:01:17.209473Z","iopub.execute_input":"2024-12-11T02:01:17.209682Z","iopub.status.idle":"2024-12-11T02:01:17.217639Z","shell.execute_reply.started":"2024-12-11T02:01:17.209660Z","shell.execute_reply":"2024-12-11T02:01:17.216696Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv', header = True, index = False)","metadata":{"execution":{"iopub.status.busy":"2024-12-11T02:04:17.938665Z","iopub.execute_input":"2024-12-11T02:04:17.939108Z","iopub.status.idle":"2024-12-11T02:04:18.025151Z","shell.execute_reply.started":"2024-12-11T02:04:17.939047Z","shell.execute_reply":"2024-12-11T02:04:18.024261Z"},"trusted":true},"outputs":[],"execution_count":null}]}