我正在尝试使用下面的代码段加载keras模型:
from tensorflow import keras
from PIL import Image, ImageOps
import numpy as np
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)
# Load the model
model = keras.models.load_model('keras_model.h5')
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image
image = Image.open("YES/1.jpg")
#resize the image to a 224x224 with the same strategy as in TM2:
#resizing the image to be at least 224x224 and then cropping from the center
size = (224, 224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
#turn the image into a numpy array
image_array = np.asarray(image)
# display the resized image
image.show()
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
print(prediction)
当我执行上述代码我得到以下错误:
文件"C:\Program Data\Anaconda3\lib\site-pack\tenstorflow\python\keras\Engine\base_layer.py",第446行,from_config返回cls(**config)
文件“C:\ProgramData\Anaconda3\lib\site packages\tensorflow\python\keras\engine\input\u layer.py”,第80行,在init raise ValueError('无法识别的关键字参数:',kwargs.keys())中
无法识别的关键字参数:dict_keys
在训练模型和加载模型时检查tf的版本。两者应为同一版本,否则可能发生此类错误。我在GoogleColab上也遇到了同样的问题,当时我在最新的tf版本上训练我的模型,而在我试图加载该模型的机器上,tf的版本不同。所以在导入tf之前,我在googlecolab中安装了相同版本的tf。它就像一个符咒。
您应该在以下需求中运行它
Keras==2.2.4 tenstorflow==1.15.0枕头==7.0.0
加上贾斯汀已经提到的。当我尝试使用使用TensorFlow 2.3培训的模型运行推理脚本时,遇到了这个问题。1在安装了TensorFlow 1.15的环境中。
我试图从我的jar启动另一个Java进程,我使用的是ProcessBuilder: 错误:无法创建Java虚拟机。错误:发生致命异常。程序将退出。无法识别的选项:-类路径“C:\absoulte\path\library.jar;C:\absoulte\path2\library2.jar;C:\absoulte\path3\library3.jar”
Keras有两种类型的模型,序贯模型(Sequential)和函数式模型(Model),函数式模型应用更为广泛,序贯模型是函数式模型的一种特殊情况。 两类模型有一些方法是相同的: model.summary():打印出模型概况,它实际调用的是keras.utils.print_summary model.get_config():返回包含模型配置信息的Python字典。模型也可以从它的config
Keras有两种类型的模型,顺序模型(Sequential)和泛型模型(Model) 两类模型有一些方法是相同的: model.summary():打印出模型概况 model.get_config():返回包含模型配置信息的Python字典。模型也可以从它的config信息中重构回去 config = model.get_config() model = Model.from_config(con
我的活动中有这个事件处理程序: 在Android TV设备模拟器中调试时,我可以看到KEYCODE_DPAD_LEFT和KEYCODE_MEDIA_PLAY_PAUSE,当我按下方向板扩展控制中的按钮时。 但当我按“快进”或“快退”媒体键时,会触发“向上键”事件,但键代码“无法识别”。 KeyEvent{action=action\u UP,keyCode=keyCode\u UNKNOWN,sc
在 Keras 中有两类主要的模型:Sequential 顺序模型 和 使用函数式 API 的 Model 类模型。 这些模型有许多共同的方法和属性: model.layers 是包含模型网络层的展平列表。 model.inputs 是模型输入张量的列表。 model.outputs 是模型输出张量的列表。 model.summary() 打印出模型概述信息。 它是 utils.print_sum
我使用JHipster以Gradle作为构建工具生成了应用程序。 当我创建实体时,我添加了过滤支持,这会生成JPA静态元模型。但是IntelliJ无法识别元模型。 我在IntelliJ上启用了注释处理器设置,但它似乎不起作用。 为了让IntelliJ识别JPA静态元模型,我必须更改哪些设置?
目前为止,我们使用函数时所用的参数都是位置参数,即传入函数的实际参数必须与形式参数的数量和位置对应。而本节将介绍的关键字参数,则可以避免牢记参数位置的麻烦,令函数的调用和参数传递更加灵活方便。 关键字参数 是指使用形式参数的名字来确定输入的参数值。通过此方式指定函数实参时,不再需要与形参的位置完全一致,只要将参数名写正确即可。 因此,Python 函数的参数名应该具有更好的语义,这样程序可以立刻明
我已经安装了PocketSphinx演示,它在Ubuntu和Eclipse下运行良好,但是尽管尝试过,我还是不知道如何添加对多个单词的识别。 我只想让代码识别单个单词,然后我可以在代码中,例如“up”、“down”、“left”、“right”。我不想识别句子,只想识别单个单词。 在这方面的任何帮助都将不胜感激。我发现其他用户也有类似的问题,但到目前为止还没有人知道答案。 让我困惑的一件事是,为什