Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow:tf.contrib.data中dataset.map()的不兼容类型_Tensorflow_Tensorflow Datasets - Fatal编程技术网

Tensorflow:tf.contrib.data中dataset.map()的不兼容类型

Tensorflow:tf.contrib.data中dataset.map()的不兼容类型,tensorflow,tensorflow-datasets,Tensorflow,Tensorflow Datasets,将哈希表查找与tf.contrib.Dataset.map()一起使用时,会失败,并出现以下错误: TypeError:在op'hash\u table\u Lookup'中,输入类型([tf.string,tf.string,tf.int32])与预期类型([tf.string\u ref,tf.string,tf.int32])不兼容。 要复制的代码: from __future__ import absolute_import from __future__ import division

将哈希表查找与
tf.contrib.Dataset.map()
一起使用时,会失败,并出现以下错误:

TypeError:在op'hash\u table\u Lookup'中,输入类型([tf.string,tf.string,tf.int32])与预期类型([tf.string\u 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\u ref
tf.string
不兼容

奇怪的是,它期望的是
tf.string\u ref
而不是
tf.string
。有人知道为什么会这样吗?我能做些什么


这些问题与
table_ref
tf.string_ref
有关,这是TensorFlow 1.3中修复的一个错误。如果您使用的是TensorFlow 1.2,则以下变通方法应适用:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

# Use internal library implementation of `lookup_ops` in TensorFlow 1.2.
from tensorflow.python.ops import lookup_ops
initializer = lookup_ops.KeyValueTensorInitializer(
    ['one', 'two', 'three'], [1, 2, 3])
hash_table = lookup_ops.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))
在TensorFlow 1.2之前,
tf.contrib.lookup
库用于表示查找表,而在内部库(从1.3开始用于实现
tf.contrib.lookup
中)中则使用了更现代、更兼容的库