[英]No OpKernel was registered to support Op 'HashTableV2' with these attrs. Registered devices: [CPU,GPU], Registered kernels:
I am coding with tensorflow 1.5.0, python 3.5. 我正在使用tensorflow 1.5.0,python 3.5进行编码。 I want to create a hashtable.
我想创建一个哈希表。 Since I intend to assign values to it later, I create it in the init function like this.(the values and shape are randomly given) enter image description here
由于我打算稍后为其分配值,因此我会在init函数中像这样创建它(值和形状是随机给出的) 在此处输入图像描述
but then I encounter a problem like this enter image description here 但是然后我遇到这样的问题在这里输入图片说明
Can anyone help me? 谁能帮我?
It seems that the implementation of HashTable in your version of TensorFlow does not provide kernels for every possible combination of key and value types. 在您的TensorFlow版本中,HashTable的实现似乎并未为键和值类型的每种可能组合提供内核。 There are two things you can do:
您可以做两件事:
According to your error message, there is a kernel implementation for 64-bit integer keys and 32-bit float values. 根据您的错误消息,对于64位整数键和32位浮点值,有一个内核实现。 So one possible fix is to simply change the data type of
keys
to tf.int64
: 因此,一种可能的解决方法是简单地将
keys
的数据类型更改为tf.int64
:
keys = tf.constant([1, 2, 3]), dtype=tf.int64)
Another possibility is to update TensorFlow to a version where this combination of key and value is implemented. 另一种可能性是将TensorFlow更新为实现键和值的组合的版本。 It seems this was added in version v1.11.0-rc0 ( see commmit ), so upgrading to that or a later version (in general it is more recommendable to upgrade to a stable version instead of a release candidate) should also fix the problem.
看来这是在v1.11.0-rc0版本中添加的 ( 请参阅commmit ),因此升级到该版本或更高版本(通常更建议升级到稳定版本而不是候选版本)也应该可以解决该问题。
The answers by @jdehesa is really great. @jdehesa的答案确实很棒。 It works for me!!!
这个对我有用!!! my tf version is 1.4, python=3.6
我的tf版本是1.4,python = 3.6
Here is my code which works: 这是我的代码有效:
import tensorflow as tf
from tensorflow.contrib.lookup import *
k = tf.range(1, 3, dtype=tf.int64)
v = tf.range(5, 7, dtype=tf.int64)
table = tf.contrib.lookup.HashTable(
tf.contrib.lookup.KeyValueTensorInitializer(k, v, key_dtype=tf.int64, value_dtype=tf.int64), -1)
out = table.lookup(tf.constant([2,1], dtype=tf.int64))
with tf.Session() as sess:
print(sess.run([k, v]))
table.init.run()
print(out.eval())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.