dshieble / Music_RNN_RBM

Generating longer musical pieces with an RNN-RBM in TensorFlow
96 stars 34 forks source link

ValueError: Shapes (2, 1, 780) and () are incompatible #12

Open EmadBinAbid opened 6 years ago

EmadBinAbid commented 6 years ago
def generate(num, x=x, size_bt=size_bt, u0=u0, n_visible=n_visible, prime_length=100):
    """
        This function handles generating music. This function is one of the outputs of the build_rnnrbm function
        Args:
            num (int): The number of timesteps to generate
            x (tf.placeholder): The data vector. We can use feed_dict to set this to the music primer. 
            size_bt (tf.float32): The batch size
            u0 (tf.Variable): The initial state of the RNN
            n_visible (int): The size of the data vectors
            prime_length (int): The number of timesteps into the primer song that we use befoe beginning to generate music
        Returns:
            The generated music, as a tf.Tensor

    """
    Uarr = tf.scan(rnn_recurrence, x, initializer=u0)
    U = Uarr[int(np.floor(prime_length/midi_manipulation.num_timesteps)), :, :]
    [_, _, _, _, _, music] = control_flow_ops.while_loop(lambda count, num_iter, *args: count < num_iter,
                                                     generate_recurrence, [tf.constant(1, tf.int32), tf.constant(num), U,
                                                     tf.zeros([1, n_visible], tf.float32), x,
                                                     tf.zeros([1, n_visible],  tf.float32)])
    return music

Error: Traceback (most recent call last): File "rnn_rbm_generate.py", line 45, in main(sys.argv[1]) File "rnn_rbm_generate.py", line 40, in main generated_music = sess.run(generate(300), feed_dict={x: song_primer}) #Prime the network with song primer and generate an original song File "C:\Users\HP\Downloads\music-github\Music_RNN_RBM\rnn_rbm.py", line 96, in generate tf.zeros([1, n_visible], tf.float32)]) File "C:\Users\HP\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3291, in while_loop return_same_structure) File "C:\Users\HP\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 3004, in BuildLoop pred, body, original_loop_vars, loop_vars, shape_invariants) File "C:\Users\HP\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2939, in _BuildLoop body_result = body(*packed_vars_for_body) File "C:\Users\HP\Downloads\music-github\Music_RNN_RBM\rnn_rbm.py", line 74, in generate_recurrence music = tf.concat(0, [music, x_out]) File "C:\Users\HP\Anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1122, in concat tensor_shape.scalar()) File "C:\Users\HP\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 848, in assert_is_compatible_with raise ValueError("Shapes %s and %s are incompatible" % (self, other)) ValueError: Shapes (2, 1, 780) and () are incompatible

Guije2018 commented 5 years ago

I used

music = tf.concat([music, x_out],0)

And

loop_vars = [time_steps, iterations, U, ut, 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])])

BLACKMogus commented 5 years ago

@Guije2018 where is the time_steps,iterations and music,they don't be define in this function

tristatian commented 5 years ago

@BLACKMogus See https://github.com/dshieble/Music_RNN_RBM/issues/7 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)