2

I am trying to do a predictions on my pretrained model , I have total of 40 classes , it is showing me predictions in epsilon numbers , I want to choose maximum from it and by using if-else , I want to classify it . It is giving me above error !

from keras.applications.inception_resnet_v2 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications import imagenet_utils
import numpy as np


def prepare_image(file):
    img_path = '/content/drive/MyDrive/test imgs/'
    img = image.load_img(img_path + file, target_size=(224, 224))
    img_array = image.img_to_array(img)
    img_array_expanded_dims = np.expand_dims(img_array, axis=0)
    return tf.keras.applications.inception_resnet_v2.preprocess_input(img_array_expanded_dims)
    
model = tf.keras.models.load_model("CNN ResNet.h5")
preprocessed_image = prepare_image('mcd.jpg')
predictions = model.predict(preprocessed_image)
print(predictions)
highest=np.argmax(prediction,axis=1)
print("Highest position : ", highest)
if(highest==0):
    print("This class is Acer")
Hamza
  • 530
  • 5
  • 27
  • So you want to obtain class names from softmax probabilities? Also at which line error was thrown? – Frightera Jan 26 '21 at 11:47
  • Is your issue resolved now? else can you share standalone code to replicate your issue?so that we can try to help you. Dont mix `keras` and `tensorflow.keras`.Thanks! –  Jul 05 '21 at 07:49

0 Answers0