1

我正在尝试将此:https ://github.com/wanasit/katakana/blob/master/notebooks/Attention-based%20Sequence-to-Sequence%20in%20Keras.ipynb应用于音乐生成而不是语言翻译。但是音乐有更多的复杂性。有没有办法确定错误来自哪里,或者我是否犯了任何概念性错误?


def create_network(n_notes, n_durations, embed_size = 100, rnn_units = 256):
    """ create the structure of the neural network """

    encoder_notes_in = Input(shape = (None,))
    encoder_durations_in = Input(shape = (None,))

    encoder_notes = Embedding(n_notes, embed_size)(encoder_notes_in)
    encoder_duration = Embedding(n_durations, embed_size)(encoder_durations_in) 

    encoder_input = Concatenate()([encoder_notes, encoder_duration])

    encoder = LSTM(rnn_units, return_sequences=True, name='lstm_enc1')(encoder_input)
    encoder = LSTM(rnn_units, return_sequences=True, name='lstm_enc2')(encoder)
    encoder_last = encoder[:,-1,:]
    print('encoder', encoder)
    print('encoder_last', encoder_last)
    # start decoder 

    decoder_input = Input(shape = (None, ))
    decoder = Embedding(n_notes, embed_size)(decoder_input)
    decoder = LSTM(rnn_units, return_sequences=True)(decoder, initial_state=[encoder_last, encoder_last])
    print('decoder', decoder)
    # end decoder

    # Attention layer
    attention = dot([decoder, encoder], axes=[2, 2])
    attention = Activation('softmax', name='attention')(attention)
    print('attention', attention)

    context = dot([attention, encoder], axes=[2,1])
    print('context', context)

    decoder_combined_context = concatenate([context, decoder])
    print('decoder_combined_context', decoder_combined_context)

    notes_output = TimeDistributed(Dense(rnn_units, activation="tanh"))(decoder_combined_context)
    notes_output = TimeDistributed(Dense(n_notes, activation="softmax"))(notes_output)
    print("notes_output", notes_output)
    durations_output = TimeDistributed(Dense(rnn_units, activation="tanh"))(decoder_combined_context)
    durations_output = TimeDistributed(Dense(n_durations, activation="softmax"))(durations_output)
    print('durations_output', durations_output)    

    model = Model([encoder_notes_in, encoder_durations_in], [notes_output, durations_output])
    opti = RMSprop(lr = 0.001)
    model.compile(loss=['categorical_crossentropy', 'categorical_crossentropy'], optimizer=opti)

    return model

model, att_model = create_network(n_notes, n_durations, embed_size, rnn_units)

encoder Tensor("lstm_enc2_7/Identity:0", shape=(None, None, 256), dtype=float32)
encoder_last Tensor("strided_slice_1:0", shape=(None, 256), dtype=float32)
decoder Tensor("lstm_7/Identity:0", shape=(None, None, 256), dtype=float32)
attention Tensor("attention_6/Identity:0", shape=(None, None, None), dtype=float32)
context Tensor("dot_13/Identity:0", shape=(None, None, 256), dtype=float32)
decoder_combined_context Tensor("concatenate_16/Identity:0", shape=(None, None, 512), dtype=float32)
notes_output Tensor("time_distributed_21/Identity:0", shape=(None, None, 461), dtype=float32)
durations_output Tensor("time_distributed_23/Identity:0", shape=(None, None, 19), dtype=float32)

ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_32:0", shape=(None, None), dtype=float32) at layer "input_32". The following previous layers were accessed without issue: ['input_31', 'input_30', 'embedding_28', 'embedding_29', 'concatenate_15', 'lstm_enc1', 'lstm_enc2']
4

0 回答 0