TensorFlow估算器ServingInputReceiver的功能与Receiver_tensors的比较:何时以及为什么?

Sum*_*ron 15 python tensorflow tensorflow-estimator

在上一个问题中,serving_input_receiver_fn探讨了的目的和结构,并在回答中

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)
Run Code Online (Sandbox Code Playgroud)

答案的作者状态(在问候receiver_tensors):

据我了解,需要将输入映射到您可以稍后检索的名称

我不清楚这种区别。实际上,(请参阅此colab),可以将相同的字典传递给featuresreceiver_tensors

从(或ServingInputReceiver docs源代码中:@estimator_export('estimator.export.ServingInputReceiver')

  • 设有:一TensorSparseTensor或字符串的字典TensorSparseTensor,指定特征将被传递到模型中。注意:如果features传递的不是字典,则将其包装在字典中,并使用“功能”作为键将其包含在单个条目中。因此,模型必须接受{'feature':tensor}形式的特征字典。TensorServingInputReceiver如果希望张量按原样传递,则可以使用 。
  • receiver_tensors:甲TensorSparseTensor或字符串的字典TensorSparseTensor,指定输入节点,其中该接收机预计要由默认进料。通常,这是一个期望序列化tf.Example原型的占位符。

阅读后,我很清楚目的features是什么。features是输入字典,然后通过图表发送。许多常见模型只有一个输入,但是您当然可以有更多输入。

因此,对我来说,关于receiver_tensors哪个“通常是期望占位的tf.Example原型的单个占位符” 的声明对我而言,建议要从TF解析receiver_tensors出单个批处理占位符。(Sequence)ExampleRecord

为什么?如果对TF Record进行了充分的预处理,那么这是否多余?如果未完全预处理,为什么要通过?featuresreceiver_tensors字典中的键应该相同吗?

有人可以请给我一个更具体的例子,说明区别和去向,直到现在

input_tensors = tf.placeholder(tf.float32, <shape>, name="input_tensors")
features = receiver_tensors =  {'input_tensors': input_tensors}
Run Code Online (Sandbox Code Playgroud)

工作...(即使可能不应该...)

小智 2

如果您在 TensorServingInputReceiver 内部进行预处理,则 receive_tensors 和功能会有所不同。在 TensorServingInputReceiver 内部进行预处理后,特征将被传递到模型。receive_tensors 是 TensorServingInputReceiver 的输入,它们可以采用 tf.Example 格式