首页 > 解决方案 > TypeError:无法将符号 Keras 输入/输出转换为 numpy 数组

问题描述

我正在尝试对我的预训练模型进行预测,我总共有 40 个类,它向我显示了 epsilon 数字的预测,我想从中选择最大值,并使用 if-else 对它进行分类。它给了我以上错误!

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")

标签: machine-learningdeep-learningneural-networkconv-neural-networkmobilenet

解决方案


推荐阅读