machine-learning - 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")
解决方案
推荐阅读
- react-native - 有什么办法可以将 TabBar 放在我的标题上
- mongodb - 如何避免集合中的重复条目?
- bash - 用 MAKEFLAGS 覆盖包含空格的 make 变量
- sql - 需要帮助从 sql 内部联接获取 SUM 数据
- python - 比较熊猫组中的不同行
- gradle - 在 gradle 中解压 rpm
- apache-spark - 从数据块中的 mlflow-registry 加载模型时出现 InvalidMountException
- python - 如何使用 Kivy/Buildozer 在 Android 上请求 ACCESS_SURFACE_FLINGER 权限?
- c# - c# 中 CefSharp DevTool 类中的事件处理程序
- powershell - 通过 PowerShell 创建新用户