给定一个类实例列表,我需要使用tf.tensor将其索引。例如:如何使用TensorFlow张量索引类实例列表
Class Something():
def __init__(self):
self.a = 1
self.b = 2
list = [Something() for a in range(0, 10)]
index_queue = tf.train.range_input_producer(len(list))
index = index_queue.dequeue()
result = list[index]
tensor = function_that_returns_tensor(result)
with tf.Session() as sess:
sess.run(tensor)
上面的代码给出以下错误:TypeError: list indices must be integers, not Tensor
并采用tf.gather(list, index)
提供了以下错误:
TypeError: Expected binary or unicode string, got <__main__.Something object at 0x7f4529fae2b0>
任何帮助,将不胜感激。谢谢!
为什么你使用'tf.constant(..)'? 'list [2]'会正常工作... –
我修改了这个问题。所以index是一个tf.tensor,它在执行图时会有一些价值。 –