Tensorflow 服务 - "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 请求(原始内容):
{"instances" : [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": "You must feed a value for placeholder tensor \'Placeholder_1\' with dtype float\n\t [[Node: Placeholder_1 = Placeholder_output_shapes=[], dtype=DT_FLOAT, shape=, _device=\"/工作:localhost/replica: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% 确定正确的方法。
我正在使用这样生成的导出服务我的模型:
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 请求(原始内容):
{"instances" : [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": "You must feed a value for placeholder tensor \'Placeholder_1\' with dtype float\n\t [[Node: Placeholder_1 = Placeholder_output_shapes=[], dtype=DT_FLOAT, shape=, _device=\"/工作:localhost/replica: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% 确定正确的方法。