TransWikia.com

*(CATEGORIES[int(prediction[0][0])])* giving me different result for single image prediction from saved model

Data Science Asked by Sazida Binta Islam on January 30, 2021

From a saved model, I am trying to predict a single image.
I followed this code – https://www.youtube.com/watch?v=A4K6D_gx2Iw

I am getting different result for two different command-

*model.predict_classes([prepare('tb2.JPG')])* 

and

prediction = model.predict([prepare('tb2.JPG')])
*(CATEGORIES[int(prediction[0][0])])*

My saved model have 2 classes, I have used sigmoid activation function for dense layer, and loss function is ‘categorical_crossentropy’
The code is –

CATEGORIES = ["ba",  "to"] 


def prepare(filepath):
    IMG_SIZE = 150  # 50 in txt-based

    img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
    img_array = img_array / 255.0
    new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
    return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)


model = tf.keras.models.load_model("test2.h5", compile=False)

prediction = model.predict([prepare('tb2.JPG')])
print(prediction)
print(CATEGORIES[int(prediction[0][0])])

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP