給定一個類實例列表,我需要使用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,它在執行圖時會有一些價值。 –