【发布时间】:2019-04-23 22:16:40
【问题描述】:
在previous question 中探讨了serving_input_receiver_fn 的用途和结构,在answer 中:
def serving_input_receiver_fn():
"""For the sake of the example, let's assume your input to the network will be a 28x28 grayscale image that you'll then preprocess as needed"""
input_images = tf.placeholder(dtype=tf.uint8,
shape=[None, 28, 28, 1],
name='input_images')
# here you do all the operations you need on the images before they can be fed to the net (e.g., normalizing, reshaping, etc). Let's assume "images" is the resulting tensor.
features = {'input_data' : images} # this is the dict that is then passed as "features" parameter to your model_fn
receiver_tensors = {'input_data': input_images} # As far as I understand this is needed to map the input to a name you can retrieve later
return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)
answer 的作者声明(关于receiver_tensors):
据我了解,这需要将输入映射到您以后可以检索的名称
我不清楚这种区别。在实践中,(参见colab),同一个字典可以同时传递给features 和receiver_tensors。
来自@estimator_export('estimator.export.ServingInputReceiver') 的source code(或ServingInputReceiver docs:
- 功能:
Tensor、SparseTensor或字符串字典到Tensor或SparseTensor,指定要传递给模型的特征。笔记: 如果features传递的不是字典,它将被包裹在字典中 单个条目,使用“功能”作为键。因此,模型必须 接受 {'feature': tensor} 形式的特征字典。您可以使用TensorServingInputReceiver如果您希望张量按原样传递。- receiver_tensors:
Tensor、SparseTensor或Tensor的字符串字典 或SparseTensor,指定此接收器期望的输入节点 默认喂食。通常,这是一个预期的占位符 序列化tf.Exampleprotos。
阅读后,我很清楚features 的目的是什么。 features 是一个输入字典,然后我通过图表发送。许多常见模型只有一个输入,但您可以或当然有更多。
那么关于receiver_tensors 的声明“通常,这是一个期望序列化tf.Example protos 的单个占位符。”对我来说,这表明receiver_tensors 需要一个从TF 解析的(Sequence)Examples 的单个批处理占位符Records。
为什么?如果 TF Records 被完全预处理,那么这是多余的吗?如果它没有完全预处理,为什么会通过呢? features 和 receiver_tensors 字典中的键是否应该相同?
谁能提供一个更具体的例子来说明差异以及现在的情况
input_tensors = tf.placeholder(tf.float32, <shape>, name="input_tensors")
features = receiver_tensors = {'input_tensors': input_tensors}
有效...(即使它不应该...)
【问题讨论】:
标签: python tensorflow tensorflow-estimator