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-



prediction = model.predict([prepare('tb2.JPG')])

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')])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.