Tensorflow mnist导出示例中使用的tf.parse_示例

Tensorflow mnist导出示例中使用的tf.parse_示例,tensorflow,tensorflow-serving,Tensorflow,Tensorflow Serving,我是tensorflow新手,正在阅读tensorflow示例中的mnist_export.py 有一件事我无法理解: sess = tf.InteractiveSession() serialized_tf_example = tf.placeholder(tf.string, name='tf_example') feature_configs = { 'x': tf.FixedLenFeature(shape=[784], dtype=tf.float32),

我是tensorflow新手,正在阅读tensorflow示例中的mnist_export.py

有一件事我无法理解:

  sess = tf.InteractiveSession()
  serialized_tf_example = tf.placeholder(tf.string, name='tf_example')
  feature_configs = {
      'x': tf.FixedLenFeature(shape=[784], dtype=tf.float32),
  }
  tf_example = tf.parse_example(serialized_tf_example, feature_configs)
  x = tf.identity(tf_example['x'], name='x')  # use tf.identity() to assign name
上面的序列化示例是张量

我已经阅读了api文档,但似乎
序列化
是序列化的
示例
协议,如:

serialized = [
  features
    { feature { key: "ft" value { float_list { value: [1.0, 2.0] } } } },
  features
    { feature []},
  features
    { feature { key: "ft" value { float_list { value: [3.0] } } }
]

那么如何理解
tf\u example=tf.parse\u example(序列化的\u tf\u example,功能配置)
这里作为
serialized\u tf\u example
是张量,而不是
example
proto?

这里
serialized\u tf\u example
tf.train.example
的序列化字符串。有关用法,请参阅。第二章给出了一些示例链接


tf_example.SerializeToString()将
tf.train.example
转换为字符串,而tf.parse_示例将序列化字符串解析为dict。

下面提到的代码提供了使用parse_示例的简单示例

import tensorflow as tf
sess = tf.InteractiveSession()
serialized_tf_example = tf.placeholder(tf.string, shape=[1], name='serialized_tf_example')
feature_configs = {'x': tf.FixedLenFeature(shape=[1], dtype=tf.float32)}
tf_example = tf.parse_example(serialized_tf_example, feature_configs)

feature_dict = {'x': tf.train.Feature(float_list=tf.train.FloatList(value=[25]))}
example = tf.train.Example(features=tf.train.Features(feature=feature_dict))
f = example.SerializeToString()


sess.run(tf_example,feed_dict={serialized_tf_example:[f]})