{"cells":[{"metadata":{},"cell_type":"markdown","source":"### IMPORTANT UPDATE\nThere is no more **Cider apple rust** class in the label csv file"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nfrom PIL import Image\nimport os\n\n# Visialisation\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nsns.set(style=\"whitegrid\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"root_dir = '../input/plant-pathology-2021-fgvc8/'\nos.listdir(root_dir)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train = pd.read_csv(os.path.join(root_dir, 'train.csv'))\ndf_submit = pd.read_csv(os.path.join(root_dir, 'sample_submission.csv'))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"There are 5 types of diseases and 1 healthy class:\n\n- Healthy\n- Scab\n- Frog eye leaf spot\n- Complex\n- Powdery mildew\n- Rust\n\nA sample plant can have multiple of those diseases simutanuously."},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"There are: \", len(df_train['labels'].unique()), \" classes in the training data\")\nprint('The labels are: ', df_train['labels'].unique())\n\nax = plt.subplots(figsize=(18, 6))\nsns.set_style(\"whitegrid\")\nsns.countplot(x='labels', data=df_train);\nplt.ylabel(\"No. of Observations\", size=20);\nplt.xlabel(\"Class Name\", size=20);\nplt.xticks(rotation=90);","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"As you can see in the plot above, we are facing with the \"Imbalance Class\" issue in the training data."},{"metadata":{"trusted":true},"cell_type":"code","source":"def show_image(class_name, examples=2):\n    labels_df=df_train\n    train_images_path=os.path.join(root_dir, \"train_images\")\n    image_list = labels_df[labels_df['labels'] == class_name]['image'].sample(frac=1)[:examples].to_list()\n    plt.figure(figsize=(20,10))\n    for i, img in enumerate(image_list):\n        full_path = os.path.join(train_images_path, img)\n        img = Image.open(full_path)\n        plt.subplot(1 ,examples, i%examples +1)\n        plt.axis('off')\n        plt.imshow(img)\n        plt.title(class_name)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 1. Healthy\nFrom the class it is pretty clear that these images are of helthy trees. Let's have a look at them to understand what healthy trees look like so that we would have a baseline undersatnding."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='healthy', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 2. Scab  \nScab is serious disease of apples and ornamental crabapples, apple scab (Venturia inaequalis) attacks both leaves and fruit. The fungal disease forms pale yellow or olive-green spots on the upper surface of leaves. Dark, velvety spots may appear on the lower surface. Severely infected leaves become twisted and puckered and may drop early in the summer.\n\nSymptoms on fruit are similar to those found on leaves. Scabby spots are sunken and tan and may have velvety spores in the center. As these spots mature, they become larger and turn brown and corky. Infected fruit becomes distorted and may crack allowing entry of secondary organisms. Severely affected fruit may drop, especially when young.  \n\nAccording to the examples, scabs can be identified by:\n1. Tiny spots on the leaves.\n2. The spots are usually yellow/brown in color."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='scab', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 3. Frog eye leaf spot\nFirst, small purple spots form on the leaves. These spots gradually enlarge and eventually develop into lesions with a light tan interior, surrounded by a dark purple perimeter. Heavy infections of frog-eye leaf spot can cause leaves to turn yellow and drop.\n\nFrog eye leaf spot symptoms on tree trunks and limbs appear as cankers, which are reddish brown in colour and are slightly sunken. As the wood ages it becomes shrunken and layers of bark begin to peel back.\n\nFrog eye leaf spot also causes small purple black spots on the fruit. These spots eventually enlarge to form concentric brown rings.\n\nAccording to the examples, Frog eye leaf spots can be identified by:\n1. Small patches on the leaves.\n2. The pathes are usually brown in color.\n3. They have a distinctive ring type shape with an inner and outer rings.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='frog_eye_leaf_spot', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 4. Complex\nAccording to data description:Unhealthy leaves with too many diseases to classify visually will have the complex class, and may also have a subset of the diseases identified."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='complex', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 5. Cider apple rust\nCircular, yellow spots (lesions) appear on the upper surfaces of the leaves shortly after bloom. In late summer, brownish clusters of threads or cylindrical tubes (aecia) appear beneath the yellow leaf spots or on fruits and twigs. The spores associated with the threads or tubes infect the leaves (needles) and twigs of junipers during wet, warm weather.\n\nAccording to the examples, Cider Apple Rusts can be identified by:\n1. Small to Large patches on the leaves.\n2. The pathes are usually Yellow to Reddish in color.\n3. They have a distinctive color and yellow-red ring type structure when fully grown."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='cider_apple_rust', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 6. Powdery Mildew\nPowdery mildew is a fungal disease that affects a wide range of plants.\n\nPowdery mildew is one of the easier plant diseases to identify, as its symptoms are quite distinctive. Infected plants display white powdery spots on the leaves and stems. The lower leaves are the most affected, but the mildew can appear on any above-ground part of the plant. As the disease progresses, the spots get larger and denser as large numbers of asexual spores are formed, and the mildew may spread up and down the length of the plant.\n\nAccording to the examples, Powdery Mildew can be identified by:\n1. Large patches on the leaves.\n2. The leaves look like having some powerdy residue on them.\n3. The pathes/residue look white in color."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='powdery_mildew', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 7. Scab + Frog eye leaf spot\nThis is a combination of Scab and Grog eye leaf spot on single image\n\nAs seen in the images the leaves have small brown spots charecteristic of Scab, but larger ring shaped spots as well showing presence of Frog eye leaf spot as well."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='scab frog_eye_leaf_spot', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 8. Scab + Frog eye leaf spot + Complex\nThis suggests that these images will be similar to the previous class... But might have some additional diseases as well. \n\nWe can see traces of Scab and Frog eye leaf spot majorly. Apart from those there is a hint of some other rusty disease which we have not encountered yet..."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='scab frog_eye_leaf_spot complex', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 9. Frog eye leaf spot + Complex\nSimilarly it is a combination of Frog eye leaf spot and some unkown disease. "},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='frog_eye_leaf_spot complex', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 10. Rust + Frog eye leaf spot\nSimilarly this is a combination of Rust and Frog eye leaf spot. "},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='rust frog_eye_leaf_spot', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 11. Powdery Mildew + complex\nThis will have powdery mildew and some unknown disease in the images."},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='powdery_mildew complex', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## 12. Rust + Complex\nThe images have the charecteristic rust sopt with some smaller spots and some brown pathces pertaining to some other disease. "},{"metadata":{"trusted":true},"cell_type":"code","source":"show_image(class_name='rust complex', examples=4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Conclusion\n\n- Honestly, as a non-professional, it is pretty hard for me to distinguish the types of diseases from the pictures. Especially the difference between \"Complex\" and some compound type e.g. \"Frog eye leaf spot + Complex\"\n\n- However, we could see a \"imbalanced class\" issue from the statistics. Thus, I think we should really consider how to handle with the \"imblanced class\" issue better."}],"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":4,"nbformat_minor":4}