{"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":"markdown","source":"<h1><center> Classify foliar diseases in durain trees</center></h1>","metadata":{}},{"cell_type":"markdown","source":"#  1. Problem Statement ？\nDurain are one of the most important temperate fruit crops in Thailand. Foliar (leaf) diseases pose a major threat to the overall productivity and quality of Durain orchards. The current process for disease diagnosis in durain orchards is based on manual scouting by humans, which is time-consuming and expensive.\n\nThe main objective of the competition is to develop machine learning-based models to accurately classify a given leaf image from the test dataset to a particular disease category, and to identify an individual disease from multiple disease symptoms on a single leaf image.","metadata":{}},{"cell_type":"markdown","source":"## libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n%matplotlib inline\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport cv2\nimport os\nimport warnings\nwarnings.filterwarnings('ignore')\nimport tensorflow as tf\nimport random\nimport albumentations as A\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.layers import Dense,Activation,Flatten, Conv2D, MaxPooling2D\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.callbacks import ModelCheckpoint,EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2022-02-17T09:51:50.936361Z","iopub.execute_input":"2022-02-17T09:51:50.936669Z","iopub.status.idle":"2022-02-17T09:51:50.946783Z","shell.execute_reply.started":"2022-02-17T09:51:50.936639Z","shell.execute_reply":"2022-02-17T09:51:50.945872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. About Dataset","metadata":{}},{"cell_type":"code","source":"train_image_path = '../input/plant-pathology-2021-fgvc8/train_images'\ntest_image_path = '../input/plant-pathology-2021-fgvc8/test_images'\ntrain_df_path = '../input/plant-pathology-2021-fgvc8/train.csv'\ntest_df_path = '../input/plant-pathology-2021-fgvc8/sample_submission.csv'","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-17T09:51:50.948400Z","iopub.execute_input":"2022-02-17T09:51:50.948872Z","iopub.status.idle":"2022-02-17T09:51:50.958937Z","shell.execute_reply.started":"2022-02-17T09:51:50.948844Z","shell.execute_reply":"2022-02-17T09:51:50.958306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> 📌**Note**:\n* `train.csv` contains information about the image files available in `train_images`. It contains 18632 rows(images) with 2 columns i.e (image , labels )\n* `test.csv` The test set images. This competition has a hidden test set: only three images are provided here as samples while the remaining 5,000 images will be available to your notebook once it is submitted.","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_csv(train_df_path)\ndf_test=pd.read_csv(test_df_path)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T09:51:50.959949Z","iopub.execute_input":"2022-02-17T09:51:50.960252Z","iopub.status.idle":"2022-02-17T09:51:50.991173Z","shell.execute_reply.started":"2022-02-17T09:51:50.960226Z","shell.execute_reply":"2022-02-17T09:51:50.990348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test","metadata":{"execution":{"iopub.status.busy":"2022-02-17T09:51:50.994093Z","iopub.execute_input":"2022-02-17T09:51:50.994619Z","iopub.status.idle":"2022-02-17T09:51:51.003581Z","shell.execute_reply.started":"2022-02-17T09:51:50.994554Z","shell.execute_reply":"2022-02-17T09:51:51.002843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.labels.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T09:51:51.004995Z","iopub.execute_input":"2022-02-17T09:51:51.005561Z","iopub.status.idle":"2022-02-17T09:51:51.017120Z","shell.execute_reply.started":"2022-02-17T09:51:51.005518Z","shell.execute_reply":"2022-02-17T09:51:51.016391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(14,10))\nlabels = sns.barplot(df_train.labels.value_counts().index,df_train.labels.value_counts())\nfor item in labels.get_xticklabels():\n    item.set_rotation(40)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T10:13:13.788367Z","iopub.execute_input":"2022-02-17T10:13:13.789120Z","iopub.status.idle":"2022-02-17T10:13:14.124561Z","shell.execute_reply.started":"2022-02-17T10:13:13.789071Z","shell.execute_reply":"2022-02-17T10:13:14.123881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> 📌**Note**:\n* We have multiple labels for eg. label can be **scab** or **scab and rust**\n* Main labels are - **scab** , **healthy** , **frog_eye_leaf_spot** , **rust** , **complex** and **powdery_mildew**\n","metadata":{}},{"cell_type":"markdown","source":"## Batch Visualisation of Images ","metadata":{}},{"cell_type":"code","source":"def batch_visualize(df,batch_size,path):\n    sample_df = df_train.sample(9)\n    image_names = sample_df[\"image\"].values\n    labels = sample_df[\"labels\"].values\n    plt.figure(figsize=(13, 12))\n    \n    for image_ind, (image_name, label) in enumerate(zip(image_names, labels)):\n        plt.subplot(3, 3, image_ind + 1)\n        image = cv2.imread(os.path.join(path, image_name))\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        plt.imshow(image)\n        plt.title(f\"{label}\", fontsize=13)\n        plt.axis(\"off\")\n    plt.show()\n    \nbatch_visualize(df_train,9,train_image_path)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T09:51:51.343746Z","iopub.execute_input":"2022-02-17T09:51:51.344447Z","iopub.status.idle":"2022-02-17T09:51:59.697120Z","shell.execute_reply.started":"2022-02-17T09:51:51.344407Z","shell.execute_reply":"2022-02-17T09:51:59.696205Z"},"trusted":true},"execution_count":null,"outputs":[]}]}