{"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 pandas as pd\nimport numpy as np\nimport cv2 \nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.applications.efficientnet import preprocess_input\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.preprocessing.image import img_to_array\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-26T15:02:37.597423Z","iopub.execute_input":"2022-08-26T15:02:37.598348Z","iopub.status.idle":"2022-08-26T15:02:37.60628Z","shell.execute_reply.started":"2022-08-26T15:02:37.598309Z","shell.execute_reply":"2022-08-26T15:02:37.605173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = load_model('../input/my-model-trained/epoch-05-val_acc-0.7344.h5')","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:02:37.611269Z","iopub.execute_input":"2022-08-26T15:02:37.611795Z","iopub.status.idle":"2022-08-26T15:02:50.124005Z","shell.execute_reply.started":"2022-08-26T15:02:37.611762Z","shell.execute_reply":"2022-08-26T15:02:50.122846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/mayo-clinic-strip-ai/test.csv')\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:02:50.127054Z","iopub.execute_input":"2022-08-26T15:02:50.127449Z","iopub.status.idle":"2022-08-26T15:02:50.151464Z","shell.execute_reply.started":"2022-08-26T15:02:50.127413Z","shell.execute_reply":"2022-08-26T15:02:50.150624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df[\"file_path\"]  = test_df[\"image_id\"].apply(lambda x: \"../input/jpg-images-strip-ai/test/\" + x + \".jpg\")","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:02:50.154037Z","iopub.execute_input":"2022-08-26T15:02:50.154357Z","iopub.status.idle":"2022-08-26T15:02:50.164933Z","shell.execute_reply.started":"2022-08-26T15:02:50.154332Z","shell.execute_reply":"2022-08-26T15:02:50.163856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import img_to_array, load_img\nimport openslide\nfrom openslide import OpenSlide\nfrom PIL import Image\nimport tensorflow as tf\nimport cv2\ndef preprocess(image_path):\n    image = cv2.imread(image_path)[:,:,::-1]\n    img = cv2.resize(image, (512,512))\n    img = img_to_array(img)\n    return img","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:02:50.167793Z","iopub.execute_input":"2022-08-26T15:02:50.168184Z","iopub.status.idle":"2022-08-26T15:02:50.17501Z","shell.execute_reply.started":"2022-08-26T15:02:50.168147Z","shell.execute_reply":"2022-08-26T15:02:50.173742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntest1=[]\nfor i in test_df['file_path']:\n    x1=preprocess(i)\n    test1.append(x1)\ntest1=np.array(test1)\n\ncnn_pred=model.predict(test1)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:06:42.68763Z","iopub.execute_input":"2022-08-26T15:06:42.688001Z","iopub.status.idle":"2022-08-26T15:06:43.085457Z","shell.execute_reply.started":"2022-08-26T15:06:42.687966Z","shell.execute_reply":"2022-08-26T15:06:43.084387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.DataFrame(test_df[\"patient_id\"].copy())\nsub[\"CE\"] = cnn_pred[:,0]\nsub[\"CE\"] = sub[\"CE\"].apply(lambda x : 0 if x<0 else x)\nsub[\"CE\"] = sub[\"CE\"].apply(lambda x : 1 if x>1 else x)\nsub[\"LAA\"] = 1- sub[\"CE\"]\n\nsub = sub.groupby(\"patient_id\").mean()\nsub = sub[[\"CE\", \"LAA\"]].round(6).reset_index()\nsub","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:06:44.742543Z","iopub.execute_input":"2022-08-26T15:06:44.74289Z","iopub.status.idle":"2022-08-26T15:06:44.764177Z","shell.execute_reply.started":"2022-08-26T15:06:44.74286Z","shell.execute_reply":"2022-08-26T15:06:44.763148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv(\"submission.csv\", index = False)\nsub","metadata":{"execution":{"iopub.status.busy":"2022-08-26T15:06:47.52916Z","iopub.execute_input":"2022-08-26T15:06:47.530397Z","iopub.status.idle":"2022-08-26T15:06:47.549392Z","shell.execute_reply.started":"2022-08-26T15:06:47.530354Z","shell.execute_reply":"2022-08-26T15:06:47.548246Z"},"trusted":true},"execution_count":null,"outputs":[]}]}