python - Tensorflow 服务 - “您必须为占位符张量“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]}
我得到的错误如下:
{ "error": "您必须为占位符张量 \'Placeholder_1\' 提供一个值,其 dtype 为 float\n\t [[Node: Placeholder_1 = Placeholder_output_shapes=[], dtype=DT_FLOAT, shape=, _device=\"/job :localhost/replica:0/task:0/device:CPU:0\"]]" }
有谁知道我做错了什么?
解决方案
对于那些寻求这个问题的答案的人,我会试一试。
导出模型时,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 文档非常简短,尤其是关于 simple_save 函数。这是我可以使它工作的唯一方法,但我不能 100% 确定正确的方法。
推荐阅读
- python - 通过 conda 安装 python 3.5 得到无法满足的错误“backport.os”
- java - 添加 Spring Security 时,带有 Mapstruct 构建的 Spring Boot 失败
- javascript - azure-graph 产生 Request_BadRequest: Invalid domain name in the request url
- microsoft-graph-api - 如何获取 ItemAttachment 内容字节以保存邮件附件?
- jquery - 确保完成 jquery 动画
- sorting - Android Studio 对 ListView 中 TextView 中的值进行排序
- angular - 我有json结果。它有一个数据属性 searchedSchools。如何将其值分配给学校O:可观察的
在订阅方法中 - swift - WatchOS 背景色动画
- python - ajax 中缺少 csrf 令牌
- python - 蟒蛇硒-
发生在 - len(driver.find_Elements(locatortype,locator)) > 0