I have trained the model on 40 classes and I have trained it by removing the top layer but it is throwing an error . Now In the next block of colab if I load the model for predictions it is not giving results
from keras.applications.inception_resnet_v2 import preprocess_input
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications import imagenet_utils
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 are",predictions)
results = imagenet_utils.decode_predictions(predictions)
question from:
https://stackoverflow.com/questions/65897940/valueerror-decode-predictions-expects-a-batch-of-predictions-i-e-a-2d-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…