Python Tensorflow服务-“;必须为占位符张量\';占位符_1\'&引用;
我正在使用以下导出为我的模型提供服务:Python Tensorflow服务-“;必须为占位符张量\';占位符_1\'&引用;,python,tensorflow,tensorflow-serving,Python,Tensorflow,Tensorflow Serving,我正在使用以下导出为我的模型提供服务: 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 + 'mode
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]}
我得到的错误如下:
{“错误”:“您必须使用dtype float\n\t[[Node:placeholder\u 1=placeholder\u output\u shapes=[],dtype=DT\u float,shape=,\u device=\”/job:localhost/replica:0/task:0/device:CPU:0\“]”}
有人知道我做错了什么吗?你必须确保你的两个占位符
features\u placeholder
和labels\u placeholder
的形状对应于两个变量features\u feed
和labels\u 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张量命名为“预测”,因此在保存模型之前,我现在可以在图形模式下获取该张量:
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文档非常简短,特别是关于简单的保存函数。这是我唯一能让它工作的方法,但我不是100%确定正确的方法。你能提供你提到的三点中的代码,以便我们追踪我编辑的错误的原因吗Hi@DavidCruz你能解决你的问题吗?我也有类似的经历。这个链接有我的问题:@DavidCruz我也得到了一些类似的错误。你能解决吗?我已经用可能的答案更新了我的问题。请随意试用。变量特性和标签只在培训期间起作用。我的问题是关于预测API的