![](/img/trans.png)
[英]Tensorflow: InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1'
[英]Tensorflow serving - “You must feed a value for placeholder tensor \'Placeholder_1\'”
我正在使用这样生成的导出服务我的模型:
features_placeholder = tf.placeholder(tf.float32, None)
labels_placeholder = tf.placeholder(tf.float32, None)
# Training loop code
......
# Train is finished.
# Export model
tf.saved_model.simple_save(sess,param.logs_dir + 'model_export',
{"features": features_placeholder}, {"binary_classif": labels_placeholder})
然后,我正在发出以下POST请求(原始正文):
{“实例”:[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]}
我得到的错误如下:
{“ error”:“您必须使用dtype float \\ n \\ t输入占位符张量\\'Placeholder_1 \\'的值[[节点:Placeholder_1 = Placeholder_output_shapes = [],dtype = DT_FLOAT,shape =,_ device = \\” / job :localhost /副本:0 /任务:0 /设备:CPU:0 \\“]]”}
有人知道我在做什么错吗?
你必须确保你的两个占位符的形状features_placeholder
和labels_placeholder
对应于两个变量的形状features_feed
和labels_feed
避免喂食字典,当你有错误。
对于那些寻求解决此问题的人,我将尝试一下。
导出模型时,simple_save函数需要张量指针,而不是占位符。 一种方法是在定义模型时命名张量,如下所示:
def inference(features):
layer_1 = nn_layer(features, get_num_features(), get_num_hidden1(), 'layer1', act=tf.nn.relu)
logits = nn_layer(layer_1, get_num_hidden1(), get_num_classes(), 'out', act=tf.identity)
logits = tf.identity(logits, name='predictions')
return logits
由于我已将logits张量命名为'predictions',因此现在可以在保存模型之前以图形方式获取此张量:
features = graph.get_tensor_by_name('features:0')
predictions = graph.get_tensor_by_name('predictions:0')
tf.saved_model.simple_save(sess,param.logs_dir + 'model_export',
{"features": features},
{"predictions": predictions})
注意:Tensorflow文档非常简短,尤其是关于simple_save函数。 这是我可以使之正常工作的唯一方法,但是我不确定100%正确地做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.