text_plain_output_1.png
from tensorflow.keras.preprocessing.image import ImageDataGenerator

import numpy as np # linear algebra

import os

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

import tensorflow as tf

import tensorflow as tf

model = tf.keras.models.load_model('../input/cassava-abhinay/model')

model.summary()

test_datagen_v2 = ImageDataGenerator(rescale=1.0 / 255)
test_dir = '../input/cassava-leaf-disease-classification/test_images/'
test = pd.DataFrame()
test['image_id'] = os.listdir('../input/cassava-leaf-disease-classification/test_images/')
test_generator = test_datagen_v2.flow_from_dataframe(test, directory=test_dir, x_col='image_id', target_size=(448, 448), batch_size=1, class_mode=None, shuffle=False)

labels = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4}

test_generator.reset()
pred = model.predict_generator(test_generator, verbose=1, steps=len(test))
predicted_class_indices = np.argmax(pred, axis=1)
labels = dict(((v, k) for k, v in labels.items()))
predictions = [labels[k] for k in predicted_class_indices]
filenames = test_generator.filenames
results = pd.DataFrame({'image_id': filenames, 'label': predictions})