tensorflow - 如何将特征列名称添加到 Keras Estimator
问题描述
我想将特征列名称添加到已转换为 Estimator 的 Keras 模型的输入中。这将允许我将 JSON 消息发送到服务模型,我可以在其中指定功能名称。我的模型如下,有3个输入节点:
model = keras.models.Sequential()
model.add(keras.layers.Dense(300, input_dim=3))
model.add(keras.layers.PReLU())
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.Dense(2, activation='softmax'))
model.compile(optimizer='Adam',loss='categorical_crossentropy',metrics=['accuracy'])
然后我创建一个估算器:
estimator_model = keras.estimator.model_to_estimator(keras_model=model)
我的自定义输入功能是:
# Define input fn
def input_function(features, labels=None, shuffle=False):
input_fn = tf.estimator.inputs.numpy_input_fn(
x={"dept_tenure": dept_tenure,
"prior_tenure": prior_tenure,
"employ_tenure": employ_tenure},
y=labels,
shuffle=shuffle
)
return input_fn
但是,当我尝试评估模型时,出现以下错误:
ValueError: Cannot find input with name "employ_tenure" in Keras Model. It needs to match one of the following: dense_4_input
model.input_n
返回[dense_4_input]
,其中dense_4
是第一层的名称。
那么如何配置我的模型,以使输入函数中的特征名称与模型的输入名称匹配?
我查看了文档,但没有帮助。
解决方案
推荐阅读
- javascript - 在附加之前显示加载消息
- database - 以最简单和最可靠的方式将表从数据库复制到 AWS 中的数据库
- http - 问题:gwcli.utils.GatewayAPIError: Unknown error connected to http://localhost:5001/api/config
- java - kafka 被设计成有很多生产者
- macos - 从 IOUserService 锁定时,IOLock 会导致 mac OS 崩溃
- r - 如何将两种类型的图与两个 y 轴结合起来?
- list - 这是一个什么样的结构?(具有部分逆但不是共单子的单子)
- node.js - 返回旧版本的nodejs时出现问题
- python - 带有 groupby 的 Pandas 数据框滚动总和列
- django - django表单内引导模式上的复选框按钮