{"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 keras\nfrom cv2 import cv2\nimport numpy as np\nimport pandas as pd\nimport tensorflow as tf\nfrom PIL import Image\nimport matplotlib.pyplot as plt\nfrom collections import Counter\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2021-06-04T19:28:14.948528Z","iopub.execute_input":"2021-06-04T19:28:14.949265Z","iopub.status.idle":"2021-06-04T19:28:21.251395Z","shell.execute_reply.started":"2021-06-04T19:28:14.949165Z","shell.execute_reply":"2021-06-04T19:28:21.250314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = keras.models.load_model('../input/plant-effnetb3-87-300/plant_effnet_b2_300_87_model.h5')","metadata":{"execution":{"iopub.status.busy":"2021-06-04T19:28:21.252970Z","iopub.execute_input":"2021-06-04T19:28:21.253274Z","iopub.status.idle":"2021-06-04T19:28:28.449127Z","shell.execute_reply.started":"2021-06-04T19:28:21.253243Z","shell.execute_reply":"2021-06-04T19:28:28.448178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cats = ['scab frog_eye_leaf_spot', 'frog_eye_leaf_spot', 'complex', 'healthy',\n        'powdery_mildew', 'powdery_mildew complex', 'rust',\n        'rust complex', 'rust frog_eye_leaf_spot',\n        'scab', 'scab frog_eye_leaf_spot complex',\n        'frog_eye_leaf_spot complex']","metadata":{"execution":{"iopub.status.busy":"2021-06-04T19:28:28.451757Z","iopub.execute_input":"2021-06-04T19:28:28.452071Z","iopub.status.idle":"2021-06-04T19:28:28.457966Z","shell.execute_reply.started":"2021-06-04T19:28:28.452041Z","shell.execute_reply":"2021-06-04T19:28:28.456925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nIMG_SIZE = 300\nsize = (IMG_SIZE,IMG_SIZE)\n\nTEST_DIR = '../input/plant-pathology-2021-fgvc8/test_images/'\ntest_images = os.listdir(TEST_DIR)\ndatagen = ImageDataGenerator(horizontal_flip=True)\nf_list = []\ng_list = []\n\ndef pred(images):\n    for image in test_images:\n        im_name = image\n        img = Image.open(TEST_DIR + image)\n        img = img.resize(size)\n        samples = np.expand_dims(img, axis=0)\n        it = datagen.flow(samples, batch_size=10)\n        yhats = model.predict(it, steps=10, verbose=0)\n        summed = np.sum(yhats, axis=0)\n        f_list.append(cats[np.argmax(summed)])\n        g_list.append(im_name)\n    #return np.argmax(summed)\n\npred(test_images)\nfinal_list = list(zip(g_list,f_list))\nfinal_list","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2021-06-04T19:28:28.459247Z","iopub.execute_input":"2021-06-04T19:28:28.459565Z","iopub.status.idle":"2021-06-04T19:28:32.146454Z","shell.execute_reply.started":"2021-06-04T19:28:28.459535Z","shell.execute_reply":"2021-06-04T19:28:32.145689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.DataFrame(final_list, columns= ['image','labels'])\nsub_df.to_csv('./submission.csv',index=None)\nsub_df","metadata":{"execution":{"iopub.status.busy":"2021-06-04T19:28:32.147660Z","iopub.execute_input":"2021-06-04T19:28:32.148122Z","iopub.status.idle":"2021-06-04T19:28:32.177267Z","shell.execute_reply.started":"2021-06-04T19:28:32.148091Z","shell.execute_reply":"2021-06-04T19:28:32.176269Z"},"trusted":true},"execution_count":null,"outputs":[]}]}