我正在读tensorflow关于tf.feature_column.indicator_column的文档。
在本文中,有一个示例。
name = indicator_column(categorical_column_with_vocabulary_list(
'name', ['bob', 'george', 'wanda'])
columns = [name, ...]
features = tf.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
dense_tensor == [[1, 0, 0]] # If "name" bytes_list is ["bob"]
dense_tensor == [[1, 0, 1]] # If "name" bytes_list is ["bob", "wanda"]
dense_tensor == [[2, 0, 0]] # If "name" bytes_list is ["bob", "bob”]我的问题是这段代码中省略的(...)部分。我只想要一个完整的,运行的,简单的例子。我找不到一个好的例子,包括tf.Example等等。
任何人都能完成这个任务吗?
谢谢你的预支。
发布于 2019-08-02 22:53:11
我希望这是一种简单明了的可视化方式。它不会完成(...)从你的问题中,我想他们说明了如何使用tf.feature_column.indicator_column
import tensorflow as tf
colors_column = tf.feature_column.indicator_column(tf.feature_column.categorical_column_with_vocabulary_list(
key='color',
vocabulary_list=["Green", "Red", "Blue", "Yellow"]
))
input_layer = tf.feature_column.input_layer(
features={'color': tf.constant(value="Red", dtype=tf.string, shape=(1,))},
feature_columns=[colors_column])
with tf.Session() as sess:
sess.run(tf.initialize_all_tables())
print(sess.run(input_layer))对它的理解更多一点:
我强烈建议阅读this。具体来说,我真的很喜欢这张照片:

它表明,当分类列映射到整数时,指示符列反过来执行到一热/多热编码的转换。
发布于 2018-10-23 02:44:57
我自己也在努力处理TF文档。我相信第一个省略号只是为了表明一个人可以有更多的列。但是对于'parse_example‘方法,第二个输入参数('serialized')是必需的(因为你现在可能已经知道了。)
以下代码适用于我,并在评估时返回文档中描述的值:
import tensorflow as tf
name = tf.feature_column.indicator_column(tf.feature_column.categorical_column_with_vocabulary_list(
'name', ['bob', 'george', 'wanda']))
columns = [name]
feature_dict = {'name': tf.train.Feature(bytes_list=tf.train.BytesList(value=['bob', 'wanda']))}
example = tf.train.Example(features=tf.train.Features(feature=feature_dict))
tf_example = tf.parse_example(serialized=[example.SerializeToString()],
features=tf.feature_column.make_parse_example_spec(columns))
dense_tensor = tf.feature_column.input_layer(tf_example, columns)
sess = tf.InteractiveSession()
tf.tables_initializer().run()
print(dense_tensor.eval())可能还有更优雅的方法,但由于没有其他答案(对我们两个都是),我希望这会有所帮助。
https://stackoverflow.com/questions/49605330
复制相似问题