{"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 numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport pickle\nimport warnings\nwarnings.filterwarnings('ignore')\nimport keras\nimport tensorflow as tf\nfrom tensorflow.keras import Sequential \nfrom tensorflow.keras.utils import Sequence, to_categorical, plot_model\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array, ImageDataGenerator\nfrom tensorflow.keras.layers import Conv2D, Conv2DTranspose, Dense, Input, MaxPooling2D, concatenate, BatchNormalization, Activation, Dropout\nfrom tensorflow.keras.models import load_model, Model\nfrom tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping\nfrom random import sample, choice\nfrom PIL import Image\nimport albumentations as albu\n\nimport time\nimport os\nfrom tqdm.notebook import tqdm\n\n#device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-28T17:30:23.172794Z","iopub.execute_input":"2022-04-28T17:30:23.173068Z","iopub.status.idle":"2022-04-28T17:30:23.186003Z","shell.execute_reply.started":"2022-04-28T17:30:23.173024Z","shell.execute_reply":"2022-04-28T17:30:23.184091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_dens = keras.models.load_model('../input/top-weights-retinal/top-weights-na.h5')","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:30:23.188014Z","iopub.execute_input":"2022-04-28T17:30:23.188309Z","iopub.status.idle":"2022-04-28T17:30:30.449206Z","shell.execute_reply.started":"2022-04-28T17:30:23.188264Z","shell.execute_reply":"2022-04-28T17:30:30.448189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Image_Path = \"../input/aptos2019-blindness-detection/test_images/\"\nlst = os.listdir(Test_Image_Path)","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:30:34.170863Z","iopub.execute_input":"2022-04-28T17:30:34.171207Z","iopub.status.idle":"2022-04-28T17:30:34.180315Z","shell.execute_reply.started":"2022-04-28T17:30:34.171166Z","shell.execute_reply":"2022-04-28T17:30:34.179200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(lst)","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:30:36.339724Z","iopub.execute_input":"2022-04-28T17:30:36.340022Z","iopub.status.idle":"2022-04-28T17:30:36.346753Z","shell.execute_reply.started":"2022-04-28T17:30:36.339992Z","shell.execute_reply":"2022-04-28T17:30:36.345752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\ndf = pd.DataFrame(columns = [\"id_code\", \"diagnosis\"])\n\nj=0\nfor i in lst:\n    x = cv2.cvtColor(cv2.imread(Test_Image_Path + i), cv2.COLOR_BGR2RGB)\n    x = cv2.resize(x, (224,224))\n    x = cv2.addWeighted(x,4,cv2.GaussianBlur(x, (0,0), 224/40) ,-4 ,128)\n    y_p = model_dens.predict(np.expand_dims(x,axis=0))\n    if(j%100==0):\n        plt.imshow(x)\n        plt.show()\n    j+=1\n    #y_p = np.squeeze(y_p, axis=1)\n    #y_pred = np.asarray(y_test)\n    #print(y_p.shape)\n    #y_p = np.squeeze(y_p, axis=1)\n    y_pred=np.argmax(y_p,axis=1)\n    df.loc[len(df.index)] = [i.split('.')[0], int(y_pred[0])] ","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:30:45.145221Z","iopub.execute_input":"2022-04-28T17:30:45.145556Z","iopub.status.idle":"2022-04-28T17:37:15.421144Z","shell.execute_reply.started":"2022-04-28T17:30:45.145519Z","shell.execute_reply":"2022-04-28T17:37:15.420075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:44:55.819790Z","iopub.execute_input":"2022-04-28T17:44:55.820131Z","iopub.status.idle":"2022-04-28T17:44:55.839581Z","shell.execute_reply.started":"2022-04-28T17:44:55.820099Z","shell.execute_reply":"2022-04-28T17:44:55.838520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv(\"./submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-28T17:44:57.469078Z","iopub.execute_input":"2022-04-28T17:44:57.469914Z","iopub.status.idle":"2022-04-28T17:44:57.485468Z","shell.execute_reply.started":"2022-04-28T17:44:57.469866Z","shell.execute_reply":"2022-04-28T17:44:57.484592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}