Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: The shape for while_1/Merge_2:0 is not an invariant for the loop. It enters the loop with shape (1, 100), but has shape (?, 100) after one iteration. Provide shape invariants using either the shape_invariants argument of tf.while_loop or set_shape() on the loop variables #7

Open
lirus7 opened this issue Nov 14, 2017 · 3 comments

Comments

@lirus7
Copy link

lirus7 commented Nov 14, 2017

I tried running your code with slight tweaks which are no way related to this part but this doesnt seem to be working .

`
Uarr = tf.scan(rnn_recurrence, x, initializer=u0)

    U = Uarr[int(np.floor(prime_length / midi_manipulation.num_timesteps)), :, :]

    time_steps = tf.constant(1, tf.int32)

    iterations = tf.constant(num)

    u_t = tf.zeros([1, n_visible], tf.float32)

    music = tf.zeros([1, n_visible], tf.float32)


    loop_vars = [time_steps, iterations, U, u_t, x, music]
    [_, _, _, _, _, music] = tf.while_loop(lambda count, num_iter, *args: count < num_iter, generate_recurrence,
                                           loop_vars, shape_invariants=[time_steps, iterations,
                                                             U, u_t,x, tf.TensorShape([1, 15600])])

    return music`
@lirus7 lirus7 changed the title ValueError: shapes must be a (possibly nested) list of shapes. ValueError: The shape for while_1/Merge_2:0 is not an invariant for the loop. It enters the loop with shape (1, 100), but has shape (?, 100) after one iteration. Provide shape invariants using either the shape_invariants argument of tf.while_loop or set_shape() on the loop variables Nov 14, 2017
@junwoo091400
Copy link

Doesn't that message come from using tf.while_loop() ?
I had similar message, so I gave 'shape' info after 'variable' in tf.while_loop()
And, it is probably because 'music' gets concatenated every loop. So it's shape changes, eventually it will become 'num_iter' x 'n_visible' size...

@vachanshetty01
Copy link

@junwoo091400: Are you saying that you've specified the 'shape_invariants' after the 'loop_vars' in the while_loop? Or have you changed something else?

I ask only because I tried adding the 'shape_invariants' but I still get the same problem.

@Guije2018
Copy link

Guije2018 commented Dec 1, 2018

I used
loop_vars = [time_steps, iterations, U, u_t, x, music] [_, _, _, _, _, music] = tf.while_loop(lambda count, num_iter, *args: count < num_iter, generate_recurrence, loop_vars, shape_invariants=[time_steps.get_shape(), iterations.get_shape(), U.get_shape(), u_t.get_shape(),x.get_shape(), tf.TensorShape([None, None])])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants