text_html_output_1.png
from PIL import Image

import numpy as np

import numpy as np # linear algebra

import numpy as np # linear algebra

import os

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import tensorflow as tf

Id = []
import numpy as np
import pandas as pd
import os
for dirname, _, filenames in os.walk('/kaggle/input/cassava-disease-classification/train'):
    for filename in filenames:
        Id.append(os.path.join(dirname, filename))
Id[:5]

sol_train = pd.DataFrame()
sol_train = sol_train.assign(filename=Id)

sol_train['label'] = sol_train['filename']
sol_train['label'] = sol_train['label'].str.replace('/kaggle/input/cassava-disease-classification/train/', '')

sol_train['label'] = sol_train['label'].str.split('/').str[0]

Id = []
import numpy as np
import pandas as pd
import os
for dirname, _, filenames in os.walk('/kaggle/input/cassava-disease-classification/test'):
    for filename in filenames:
        Id.append(os.path.join(dirname, filename))
Id[:5]

sol_test = pd.DataFrame()
sol_test = sol_test.assign(filename=Id)

sol_test['label'] = sol_test['filename']
sol_test['label'] = sol_test['label'].str.replace('/kaggle/input/cassava-disease-classification/test/', '')

sol_test['label'] = sol_test['label'].str.split('/').str[0]

import tensorflow as tf
import numpy as np
from PIL import Image
model = tf.saved_model.load('/kaggle/input/efficientnet-cassava-disease-classification/EfficientNet')
classes = ['Cassava Bacterial Blight (CBB)', 'Cassava Brown Streak Disease (CBSD)', 'Cassava Green Mottle (CGM)', 'Cassava Mosaic Disease (CMD)', 'Healthy']

result = []
for i in sol_test.filename:
    img = Image.open(i).convert('RGB')
    img = img.resize((300, 300 * img.size[1] // img.size[0]), Image.ANTIALIAS)
    inp_numpy = np.array(img)[None]
    inp = tf.constant(inp_numpy, dtype='float32')
    class_scores = model(inp)[0].numpy()
    result.append(classes[class_scores.argmax()])
result[:5]

result = []
for i in sol_train.filename:
    img = Image.open(i).convert('RGB')
    img = img.resize((300, 300 * img.size[1] // img.size[0]), Image.ANTIALIAS)
    inp_numpy = np.array(img)[None]
    inp = tf.constant(inp_numpy, dtype='float32')
    class_scores = model(inp)[0].numpy()
    result.append(classes[class_scores.argmax()])
result[:5]

sol_train = sol_train.assign(prediction=result)

sol_train['label'] = sol_train['label'].replace({'cbb': 'Cassava Bacterial Blight (CBB)', 'cbsd': 'Cassava Brown Streak Disease (CBSD)', 'cgm': 'Cassava Green Mottle (CGM)', 'cmd': 'Cassava Mosaic Disease (CMD)', 'healthy': 'Healthy'})
sol_train.head()