{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport cv2\nimport json\nimport numpy as np \n\n\nimport torch\nimport pandas as pd\nimport seaborn as sns\nimport torch.nn as nn\nimport albumentations as A\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.model_selection import train_test_split","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df=pd.read_csv('../input/cassava-leaf-disease-classification/train.csv')\nwith open('../input/cassava-leaf-disease-classification/label_num_to_disease_map.json') as file:\n    label_num_disease_map=json.loads(file.read())\n    \ntrain_df['disease_name']=train_df.label.apply(lambda x: label_num_disease_map[str(x)] )\ntrain_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.label.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(train_df.label)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df[['label', 'disease_name']].drop_duplicates()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Dataset is highly imbalanced"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['image_path']=train_df.image_id.apply(lambda x: os.path.join('../input/cassava-leaf-disease-classification/train_images', x))\ntrain_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def load_image(imgpath):\n    img=cv2.imread(imgpath)\n    img=cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    img=cv2.resize(img, (256, 256))\n    return img","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Healthy leafs"},{"metadata":{"trusted":true},"cell_type":"code","source":"healthy_images=train_df[train_df.label==4].image_path.values[:10]\n\nfig, ax=plt.subplots(2, 5, figsize=(20, 20))\nfor idx, imgpath in enumerate(healthy_images):\n    img=load_image(imgpath)\n    ax[int(idx/5)][idx%5].imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax=plt.subplots(5, 5, sharex=True, figsize=(30, 30))\nfor rowid, label in enumerate(np.sort(train_df.label.unique())):\n    for imgid, image_path in enumerate(train_df[train_df.label == label].sample(frac=1.0, random_state=10).image_path.values[:5]):\n        img=load_image(image_path)\n        ax[rowid][imgid].imshow(img)\n        ax[rowid][imgid].set_ylabel('Label:{}'.format(label))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax=plt.subplots(5, 5, sharex=True, figsize=(30, 30))\nfor rowid, label in enumerate(np.sort(train_df.label.unique())):\n    for imgid, image_path in enumerate(train_df[train_df.label == label].sample(frac=1.0, random_state=54).image_path.values[:5]):\n        img=load_image(image_path)\n        ax[rowid][imgid].imshow(img)\n        ax[rowid][imgid].set_ylabel('Label:{}'.format(label))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"What To Expect From the Images given.\n\n\n1. Light Intensities.\n2. Bright & Dull light variations in a single image eg. (2, 4)\n3. Different shades of the image.\n4. Dense Leaves.\n5. Sparse Leaves;\n6. Zoomed out --> snap taken from long distance (5, 2)\n7. Zoomed In --> Snap taken near to the Plant (1, 1)\n8. Varied Backgrounds for different Images --> Red Soil, Black Soil, pink background etc. \n9. Leaves are more visible from the side-angles.\n10. Some Leaves are old, dried, brown spots, green+yellow, teared."},{"metadata":{"trusted":true},"cell_type":"code","source":"img=load_image(train_df.image_path.values[0])\nplt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df['img_mean']=train_df.image_path.apply(lambda x: load_image(x).mean())\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(train_df['img_mean'])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for label in train_df.label.unique():\n    print('==================')\n    print(\"Label:{}\".format(label))\n    plt.hist(  train_df[train_df.label==label].img_mean )\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"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}