没有注册任何OpKernel支持这些属性的Op'HashTableV2'。注册设备:[CPU,GPU],注册内核:

时间:2018-11-07 12:21:03

标签: python tensorflow hashtable

我正在使用tensorflow 1.5.0,python 3.5进行编码。我想创建一个哈希表。由于我打算稍后为其分配值,因此我会在init函数中像这样创建它(值和形状是随机给出的) enter image description here

但是我遇到这样的问题 enter image description here

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

在您的TensorFlow版本中,HashTable的实现似乎并未为键和值类型的每种可能组合提供内核。您可以做两件事:

  • 根据您的错误消息,存在用于64位整数键和32位浮点值的内核实现。因此,一种可能的解决方法是将keys的数据类型简单地更改为tf.int64

    keys = tf.constant([1, 2, 3]), dtype=tf.int64)
    
  • 另一种可能性是将TensorFlow更新为实现键和值的组合的版本。看来它是在版本v1.11.0-rc0see commmit)中添加的,因此也应该修复升级到该版本或更高版本(通常建议升级到稳定版本而不是候选版本)。问题。

答案 1 :(得分:0)

@jdehesa的回答确实很棒。这个对我有用!!!我的tf版本是1.4,python = 3.6

这是我的有效代码:

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