{"cells":[{"metadata":{},"cell_type":"markdown","source":"Thumbnails are created by [this notebook](https://www.kaggle.com/marutama/cassava-image-with-thumbnails).\n\nPlease, comment-out last line 'rm -rf' and re-run notebook.\n\nサムネイルは[このnotebook](https://www.kaggle.com/marutama/cassava-image-with-thumbnails)で作られています。\n\n最終行の rm -rf をコメントアウトして、notebook 再実行してください。"},{"metadata":{},"cell_type":"markdown","source":"It would be an important EDA technique to actually see all the images. It's a heavy notebook, but I made a Viewer. If it helps you, please upvote.\n\nすべての画像を、実際に見ることは重要なEDA手法でしょう。重いnotebookですがViewerを作りました。あなたの役に立つようでしたらupvoteお願いします。"},{"metadata":{"trusted":true},"cell_type":"code","source":"ls ../input/cassava-image-with-thumbnails","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **Import**"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport json\nimport shutil\nimport pandas as pd\nfrom tqdm.auto import tqdm\nfrom IPython.display import HTML","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%javascript\nIPython.OutputArea.auto_scroll_threshold = 200;","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **Load json and csv**"},{"metadata":{"trusted":true},"cell_type":"code","source":"BASE_DIR = \"../input/cassava-leaf-disease-classification/\"\nwith open(os.path.join(BASE_DIR, \"label_num_to_disease_map.json\")) as file:\n    classes = json.loads(file.read())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"classes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(os.path.join(BASE_DIR, \"train.csv\")).set_index('image_id')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **Make directories**"},{"metadata":{"trusted":true},"cell_type":"code","source":"root_name = os.path.join('.', 'images')\n#if os.path.exists(root_name):\n#    shutil.rmtree(root_name)\n#os.makedirs(root_name)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# create dir_names and do makedir\ndir_names=[]\ndir_snames=[]\nfor k in classes.keys():\n    name = os.path.join(root_name, f'{k}')\n    dir_names.append(name)\n    sname = name + 's'\n    dir_snames.append(sname)\n#    if os.path.exists(name):\n#        shutil.rmtree(name)\n#    os.makedirs(name)\n#    if os.path.exists(sname):\n#        shutil.rmtree(sname)\n#    os.makedirs(sname)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **Unzip files**"},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n!rm -rf ./images","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n!unzip -q ../input/cassava-image-with-thumbnails/images.zip ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ls ./images","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# All Images\n\nSee also [this discussion](https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/198143).\n\nClick the thumbnail image to see the original image.\n(Comment-out last line: rm -rf, and re-run this notebook)\n\nサムネイル画像をクリックするとオリジナル画像が見れます。\n(最終行のrm -rfをコメントアウトして、このnotebookを再実行すればクリック可能となります)"},{"metadata":{},"cell_type":"markdown","source":"# 0: Cassava Bacterial Blight (CBB)"},{"metadata":{},"cell_type":"markdown","source":"[Cassava Bacterial Blight (CBB)](https://en.wikipedia.org/wiki/Bacterial_blight_of_cassava)\n\nIn cassava, symptoms vary in a manner that is unique to this pathogen. Symptoms include blight, wilting, dieback, and vascular necrosis. A more diagnostic symptom visible in cassava with X. axonopodis infection are angular necrotic spotting of the leaves—often with a chlorotic ring encircling the spots. These spots begin as distinguishable moist, brown lesions normally restricted to the bottom of the plant until they enlarge and coalesce—often killing the entire leaf. A further diagnostic symptom often embodies itself as pools of gum exudate along wounds and leaf cross veins. It begins as a sappy golden liquid and hardens to form an amber colored deposit.\n\nキャッサバでは、症状はこの病原体に特有の方法で変化します。 症状には、枯死、しおれ、立ち枯れ、血管壊死などがあります。 X. axonopodis感染のキャッサバに見られるより診断的な症状は、葉の角状壊死斑点であり、多くの場合、斑点を取り囲むクロロティックリングがあります。 これらの斑点は、識別可能な湿った茶色の病変として始まり、通常は植物の底に限定され、拡大して合体します。多くの場合、葉全体が死滅します。 さらなる診断症状は、多くの場合、傷や葉の交差静脈に沿って歯茎の滲出液のプールとして現れます。 それは、生意気な金色の液体として始まり、硬化して琥珀色の堆積物を形成します。"},{"metadata":{"trusted":true},"cell_type":"code","source":"n = 0\nl_dir = dir_names[n]\ns_dir = dir_snames[n]\nhtml_str = (\n '<table border=\"1\">'\n  '<tr>')\n\nhtml_img = \"\"\nhtml_txt = \"\"\ncol_num = 10\nfor i, img in enumerate(tqdm(sorted(os.listdir(s_dir)), desc=f'[HTML]')):\n    l_img = os.path.join(l_dir, img)\n    s_img = os.path.join(s_dir, img)\n    html_img += f'<td width=\"64\"><a href=\"{l_img}\" title=\"{img} \"target=\"_blank\"><img src=\"{s_img}\"></a></td>'\n    base = os.path.splitext(img)[0]\n    html_txt += f'<td width=\"64\"><font size=\"1\">{base}</font></td>'\n    if not (i+1)%col_num :\n        html_str += '</tr>'\n        html_str += html_img\n        html_img = \"\"\n        html_str += '<tr>'\n        html_str += '</tr>'\n        html_str += html_txt\n        html_txt = \"\"\n        html_str += '<tr>'\n\nhtml_str += '</tr>'\nhtml_str += html_img\nhtml_img = \"\"\nhtml_str += '<tr>'\nhtml_str += '</tr>'\nhtml_str += html_txt\nhtml_txt = \"\"\nhtml_str += '<tr>'\n        \nhtml_str += '</tr>'\nhtml_str += '</table>'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HTML(html_str)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 1: Cassava Brown Streak Disease (CBSD)"},{"metadata":{},"cell_type":"markdown","source":"[Cassava Brown Streak Disease (CBSD)](https://en.wikipedia.org/wiki/Cassava_brown_streak_virus_disease)\n\nCBSD is characterized by severe chlorosis and necrosis on infected leaves, giving them a yellowish, mottled appearance. Chlorosis may be associated with the veins, spanning from the mid vein, secondary and tertiary veins, or rather in blotches unconnected to veins. Leaf symptoms vary greatly depending on a variety of factors. The growing conditions (i.e. altitude, rainfall quantity), plant age, and the virus species account for these differences. Brown streaks may appear on the stems of the cassava plant. Also, a dry brown-black necrotic rot of the cassava tuber exists, which may progress from a small lesion to the whole root. Finally, the roots can become constricted due to the tuber rot, stunting growth. Typically the affected plants do not possess all of these characteristics, but those that are severely affected may. Farmers may be unaware of their infected cassava crops until they are harvested and see the tuber lesions because leaves are asymptomatic. \n\nCBSDは、感染した葉の重度の白化と壊死を特徴としており、それらに黄色がかった、まだらの外観を与えます。\n白化は、中静脈から広がる静脈に関連している可能性があり、二次および三次静脈、またはむしろ静脈に接続されていないしみに関連している可能性があります。葉の症状は、さまざまな要因によって大きく異なります。成長条件（すなわち、高度、降雨量）、植物の年齢、およびウイルス種がこれらの違いを説明します。キャッサバ植物の茎に茶色の縞が現れることがあります。また、キャッサバ塊茎の乾燥した茶黒色の壊死性腐敗が存在し、小さな病変から根全体に進行する可能性があります。最後に、塊茎の腐敗により根が収縮し、発育阻害が起こる可能性があります。通常、影響を受ける植物はこれらの特性のすべてを持っているわけではありませんが、深刻な影響を受ける植物はそうかもしれません。葉は無症候性であるため、農家は、収穫されて塊茎の病変が見えるまで、感染したキャッサバ作物に気付かない可能性があります"},{"metadata":{"trusted":true},"cell_type":"code","source":"n = 1\nl_dir = dir_names[n]\ns_dir = dir_snames[n]\nhtml_str = (\n '<table border=\"1\">'\n  '<tr>')\n\nhtml_img = \"\"\nhtml_txt = \"\"\ncol_num = 10\nfor i, img in enumerate(tqdm(sorted(os.listdir(s_dir)), desc=f'[HTML]')):\n    l_img = os.path.join(l_dir, img)\n    s_img = os.path.join(s_dir, img)\n    html_img += f'<td width=\"64\"><a href=\"{l_img}\" title=\"{img} \"target=\"_blank\"><img src=\"{s_img}\"></a></td>'\n    base = os.path.splitext(img)[0]\n    html_txt += f'<td width=\"64\"><font size=\"1\">{base}</font></td>'\n    if not (i+1)%col_num :\n        html_str += '</tr>'\n        html_str += html_img\n        html_img = \"\"\n        html_str += '<tr>'\n        html_str += '</tr>'\n        html_str += html_txt\n        html_txt = \"\"\n        html_str += '<tr>'\n\nhtml_str += '</tr>'\nhtml_str += html_img\nhtml_img = \"\"\nhtml_str += '<tr>'\nhtml_str += '</tr>'\nhtml_str += html_txt\nhtml_txt = \"\"\nhtml_str += '<tr>'\n        \nhtml_str += '</tr>'\nhtml_str += '</table>'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HTML(html_str)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 2: Cassava Green Mottle (CGM)"},{"metadata":{},"cell_type":"markdown","source":"[Cassava Green Mottle (CGM)](http://www.pestnet.org/fact_sheets/cassava_green_mottle_068.htm)\n\nYoung leaves are puckered with faint to distinct yellow spots, green patterns (mosaics), and twisted margins. Usually, the shoots recover from symptoms and appear healthy. Occasionally, plants become severely stunted, edible roots are absent or, if present, they are small and woody when cooked. Detection & Inspection: Look for yellow patterns on the leaves, from small dots to irregular patches of yellow and green. Look for leaf margins that are distorted. The plants may be stunted.\n\n若い葉は、かすかにはっきりとした黄色の斑点、緑色の模様（モザイク）、ねじれた縁でしわが寄っています。通常、新芽は症状から回復し、健康に見えます。時折、植物はひどく発育不全になり、食用の根がないか、存在する場合は、調理したときに小さくて木質になります。検出と検査:小さな点から黄色と緑の不規則なパッチまで、葉の黄色のパターンを探します。歪んでいる葉の余白を探します。植物は発育不全になる可能性があります。"},{"metadata":{"trusted":true},"cell_type":"code","source":"n = 2\nl_dir = dir_names[n]\ns_dir = dir_snames[n]\nhtml_str = (\n '<table border=\"1\">'\n  '<tr>')\n\nhtml_img = \"\"\nhtml_txt = \"\"\ncol_num = 10\nfor i, img in enumerate(tqdm(sorted(os.listdir(s_dir)), desc=f'[HTML]')):\n    l_img = os.path.join(l_dir, img)\n    s_img = os.path.join(s_dir, img)\n    html_img += f'<td width=\"64\"><a href=\"{l_img}\" title=\"{img} \"target=\"_blank\"><img src=\"{s_img}\"></a></td>'\n    base = os.path.splitext(img)[0]\n    html_txt += f'<td width=\"64\"><font size=\"1\">{base}</font></td>'\n    if not (i+1)%col_num :\n        html_str += '</tr>'\n        html_str += html_img\n        html_img = \"\"\n        html_str += '<tr>'\n        html_str += '</tr>'\n        html_str += html_txt\n        html_txt = \"\"\n        html_str += '<tr>'\n\nhtml_str += '</tr>'\nhtml_str += html_img\nhtml_img = \"\"\nhtml_str += '<tr>'\nhtml_str += '</tr>'\nhtml_str += html_txt\nhtml_txt = \"\"\nhtml_str += '<tr>'\n        \nhtml_str += '</tr>'\nhtml_str += '</table>'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HTML(html_str)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 3: Cassava Mosaic Disease (CMD)"},{"metadata":{},"cell_type":"markdown","source":"[Cassava Mosaic Disease (CMD)](https://en.wikipedia.org/wiki/Cassava_mosaic_virus)\n\nThese symptoms include chlorotic mosaic of the leaves, leaf distortion, and stunted growth. Leaf stalks have a characteristic S-shape.\n\n植物全体に病徴が発現する。病徴には葉のモザイク状の白化、葉の変形、生育の阻害が含まれる。"},{"metadata":{"trusted":true},"cell_type":"code","source":"n = 3\nl_dir = dir_names[n]\ns_dir = dir_snames[n]\nhtml_str = (\n '<table border=\"1\">'\n  '<tr>')\n\nhtml_img = \"\"\nhtml_txt = \"\"\ncol_num = 10\nfor i, img in enumerate(tqdm(sorted(os.listdir(s_dir)), desc=f'[HTML]')):\n    l_img = os.path.join(l_dir, img)\n    s_img = os.path.join(s_dir, img)\n    html_img += f'<td width=\"64\"><a href=\"{l_img}\" title=\"{img} \"target=\"_blank\"><img src=\"{s_img}\"></a></td>'\n    base = os.path.splitext(img)[0]\n    html_txt += f'<td width=\"64\"><font size=\"1\">{base}</font></td>'\n    if not (i+1)%col_num :\n        html_str += '</tr>'\n        html_str += html_img\n        html_img = \"\"\n        html_str += '<tr>'\n        html_str += '</tr>'\n        html_str += html_txt\n        html_txt = \"\"\n        html_str += '<tr>'\n\nhtml_str += '</tr>'\nhtml_str += html_img\nhtml_img = \"\"\nhtml_str += '<tr>'\nhtml_str += '</tr>'\nhtml_str += html_txt\nhtml_txt = \"\"\nhtml_str += '<tr>'\n        \nhtml_str += '</tr>'\nhtml_str += '</table>'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HTML(html_str)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# 4: Healthy"},{"metadata":{"trusted":true},"cell_type":"code","source":"n = 4\nl_dir = dir_names[n]\ns_dir = dir_snames[n]\nhtml_str = (\n '<table border=\"1\">'\n  '<tr>')\n\nhtml_img = \"\"\nhtml_txt = \"\"\ncol_num = 10\nfor i, img in enumerate(tqdm(sorted(os.listdir(s_dir)), desc=f'[HTML]')):\n    l_img = os.path.join(l_dir, img)\n    s_img = os.path.join(s_dir, img)\n    html_img += f'<td width=\"64\"><a href=\"{l_img}\" title=\"{img} \"target=\"_blank\"><img src=\"{s_img}\"></a></td>'\n    base = os.path.splitext(img)[0]\n    html_txt += f'<td width=\"64\"><font size=\"1\">{base}</font></td>'\n    if not (i+1)%col_num :\n        html_str += '</tr>'\n        html_str += html_img\n        html_img = \"\"\n        html_str += '<tr>'\n        html_str += '</tr>'\n        html_str += html_txt\n        html_txt = \"\"\n        html_str += '<tr>'\n\nhtml_str += '</tr>'\nhtml_str += html_img\nhtml_img = \"\"\nhtml_str += '<tr>'\nhtml_str += '</tr>'\nhtml_str += html_txt\nhtml_txt = \"\"\nhtml_str += '<tr>'\n        \nhtml_str += '</tr>'\nhtml_str += '</table>'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"HTML(html_str)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# For Save version\n\nPlease, comment-out bellow 'rm -rf' and re-run notebook.\n\n下記の rm -rf をコメントアウトして、notebook 再実行してください。"},{"metadata":{"trusted":true},"cell_type":"code","source":"!rm -rf ./images","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}