В моем простом примере вход изначально имеет форму (3,), но один раз через тело () он будет иметь (3,2).Ни один из них не работает как shape_invariants.Любая идея, как указать форму тензора, если он изменяется в теле () цикла while?
import tensorflow as tf
repeats = 2
def body(inputs, i, iter):
outputs = tf.stack([inputs,inputs],axis=1)
return [outputs, i+1, iter]
def cond(inputs, i, iter ):
return tf.less(i,repeats)
i = tf.constant(0)
iter = tf.constant(repeats)
inputs = tf.get_variable("my_variable", initializer=tf.constant([1, 2, 3]))
with tf.Session() as sess:
tf.global_variables_initializer().run()
print(inputs.get_shape())
outputs = tf.while_loop(cond, body, loop_vars=[inputs,i, iter],shape_invariants=[tf.TensorShape([3,None]),i.get_shape(),iter.get_shape()])
print(len(outputs))
print(sess.run(outputs))
ValueError: Инвариант формы, указанный для my_variable / read: 0, не совместим с начальной формой переменной цикла.Он входит в цикл с формой (3,), но указанным инвариантом формы является (3,?).