使用带有 的哈希表查找时tf.contrib.Dataset.map()
,它会失败并出现以下错误:
TypeError: In op 'hash_table_Lookup', input types ([tf.string, tf.string, tf.int32]) are not compatible with expected types ([tf.string_ref, tf.string, tf.int32])
重现代码:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
initializer = tf.contrib.lookup.KeyValueTensorInitializer(
['one', 'two', 'three'], [1, 2, 3])
hash_table = tf.contrib.lookup.HashTable(initializer, -1)
tensor = tf.convert_to_tensor(['one', 'two', 'three'])
dataset = tf.contrib.data.Dataset.from_tensor_slices(tensor)
dataset = dataset.map(lambda k: hash_table.lookup(k))
它抱怨tf.string_ref
和tf.string
不兼容。
奇怪的是它需要 atf.string_ref
而不是 a tf.string
。有谁知道为什么会这样以及我能做些什么?
这些问题与table_ref
在tf.string_ref
这里有关。