{"cells":[{"metadata":{},"cell_type":"markdown","source":"****The Dataset of cassava plants annotated with the types of disease inflicting the plants.****\n****\n* [iCassava 2019 Fine-Grained Visual Categorization Challenge](https://arxiv.org/pdf/1908.02900.pdf) "},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport json\nimport cv2\nimport os","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Understanding train data**\n* There are two columns - image ids and labels(0,1,2,3,4)\n* there are 21,397 labeled data present as training dataset\n* There are roughly 15,000 test images for evaluation"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(\"../input/cassava-leaf-disease-classification/train.csv\")\nprint(train_df.head())\nprint(f\"\\nNumber of training images: {train_df.shape[0]}\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**About labels:**\n* This is multi-class classification with labels 0,1,2,3 and 4.\n* Each label values from 0-3 represent type of disease and label value 4 means its healthy plant leaf.\n* Imbalanced Class distribution in the training dataset"},{"metadata":{"trusted":true},"cell_type":"code","source":"#https://www.kaggle.com/isaienkov/cassava-leaf-disease-classification-data-analysis\nimg_size = {}\nfor filename in os.listdir('/kaggle/input/cassava-leaf-disease-classification/train_images/')[:100]:\n    img = cv2.imread('/kaggle/input/cassava-leaf-disease-classification/train_images/' + filename)\n    try:\n        img_size[img.shape] += 1\n    except:\n        img_size[img.shape] = 1\n        \nprint(f\"Size of each the image: {img_size}\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"with open(\"../input/cassava-leaf-disease-classification/label_num_to_disease_map.json\") as f:\n    class_dist = json.loads(f.read())\nprint(class_dist)\nsns.countplot(y=train_df.astype(str).replace(class_dist).label)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**About Each disease and its sample images** |\nThe four major diseases affecting cassava and their major symptoms include:\n*  Cassava mosaic disease (CMD) (class-3)\n    - The most widespread cassava disease in sub-Saharan Africa.  \n    - Foliar symptoms - mosaic, mottling, misshapen and twisted leaflets, and an overall reduction in size of leaves and plants, patches of normal green color mixed with different proportions of yellow and white depending on the severity\n\n\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"#helper function for plotting images\n# https://www.kaggle.com/ihelon/cassava-leaf-disease-exploratory-data-analysis \ndef image_view(image_ids,labels):\n    plt.figure(figsize=(16, 8))\n    for i,(img_id,lbl) in enumerate(zip(image_ids,labels)):\n        plt.subplot(2,3,i+1)\n        image = cv2.imread(os.path.join(\"../input/cassava-leaf-disease-classification/train_images\",img_id))\n        image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)\n        plt.imshow(image)\n        plt.axis(\"off\")\n    plt.show()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample = train_df[train_df.label==3].sample(6)\nids = sample.image_id.values\nlabels = sample.label.values\nimage_view(ids,labels)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"*  **Cassava brown streak disease (CBSD)** (class-1)\n    - CBSD is presently the most severe of the cassava diseases.\n    - It is vectored by white flies and can also be transmitted through infected cuttings. \n    - leaf symptoms consist of a characteristic yellow or necrotic vein banding which may enlarge and coalesce to form comparatively large yellow patches.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"sample = train_df[train_df.label==1].sample(6)\nids = sample.image_id.values\nlabels = sample.label.values\nimage_view(ids,labels)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* **Cassava bacterial blight(CBB)** (class-0)\n    -  major bacterial disease which is common in moist areas\n    - leaf symptoms include; black leaf spots and blights, angular leaf spots, and premature drying and shedding of leaves due to the wilting of young leaves and severe attack.\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"sample = train_df[train_df.label==0].sample(6)\nids = sample.image_id.values\nlabels = sample.label.values\nimage_view(ids,labels)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* **Cassava green mite (CGM)** (class-2)\n    - This disease causes white spotting of leaves, which increase from the initial small spots to cover the entire leaf causing loss of chlorophyll.\n    -  Leaves damaged by CGM may also show mottled symptoms which can be confused with symptoms of (CMD)."},{"metadata":{"_kg_hide-input":false,"trusted":true},"cell_type":"code","source":"sample = train_df[train_df.label==2].sample(6)\nids = sample.image_id.values\nlabels = sample.label.values\nimage_view(ids,labels)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Dataset Complexity**\n1. The different image backgrounds and scales\n2. The time of day the image was acquired\n3. Multiple co-occurring diseases on one plant\n4. The poor focus of some images."},{"metadata":{"trusted":true},"cell_type":"code","source":"submission = pd.read_csv(\"../input/cassava-leaf-disease-classification/sample_submission.csv\")\nprint(f\"Submission file : \\n{submission.head()}\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"[Train and inference efficientNet](https://www.kaggle.com/shivanandmn/efficientnet-pytorch-lightning-train-inference) - Notebook-1\n\n[Train and inference simple CNN and Pytorch ](https://www.kaggle.com/shivanandmn/cnn-pytorch-lightning-beginners-model)- Notbook-2\n\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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}