【发布时间】:2019-01-12 03:45:42
【问题描述】:
只要还有一些列使用tf.while_loop,我就会尝试将张量切成小块。
注意:我使用这种方式是因为我无法在图形构建时(没有会话)循环占位符中的值,该值被视为张量而不是整数。
[ 5 7 8 ]
[ 7 4 1 ] =>
[5 7 ] [ 7 8 ]
[7 4 ] [ 4 1 ]
这是我的代码:
i = tf.constant(0)
result = tf.subtract(tf.shape(f)[1],1)
c = lambda result : tf.greater(result, 0)
b = lambda i: [i+1, tf.slice(x, [0,i],[2, 3])]
o= tf.while_loop(c, b,[i])
with tf.Session() as sess:
print (sess.run(o))
但是,我得到了这个错误:
ValueError: The two structures don't have the same nested structure.
First structure: type=list str=[<tf.Tensor 'while_2/Identity:0' shape=() dtype=int32>]
Second structure: type=list str=[<tf.Tensor 'while_2/add:0' shape=() dtype=int32>, <tf.Tensor 'while_2/Slice:0' shape=(2, 3) dtype=int32>]
我想每次都返回子张量
【问题讨论】:
标签: python loops tensorflow slice tensor