2017-06-17 7 views
0

でdataset.mapのための互換性のないタイプ()tf.contrib.Dataset.map()と、ハッシュテーブルルックアップを使用している場合、それは次のエラーで失敗します。再現するTensorflow:tf.contrib.data

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_reftf.stringは互換性がありません。

tf.string_refであり、tf.stringではないと奇妙です。なぜこれが事実であり、私はそれについて何ができるのか誰にも分かりますか?

table_reftf.string_refhereに関連しています。

答えて

1

これはTensorFlow 1.3で修正されたバグです。あなたがTensorFlow 1.2を使用している場合は、以下の回避策は動作するはずです:TensorFlow 1.2まで、tf.contrib.lookupライブラリは内部ライブラリに(以降1.3からtf.contrib.lookupを実装するために使用される)のに対し、ルックアップテーブルを表すために"reference types"を使用

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)) 

までより現代的で互換性のある"resource types"が使用されます。