尝试对音乐数据进行转移学习

我正在尝试在以下存储库中执行github代码:

https://github.com/shubham3121/music-generation-using-rnn 错误在于以下功能:

def generate():
    """ Generate a piano midi file """
    #load the notes used to train the model
    with open('data/notes','rb') as filepath:
        notes = pickle.load(filepath)

    # Get all pitch names
    pitchnames = sorted(set(item for item in notes))
    # Get all pitch names
    n_vocab = len(set(notes))

    print('Initiating music generation process.......')

    network_input = get_inputSequences(notes,pitchnames,n_vocab)
    model = create_network(normalized_input,n_vocab)
    print('Loading Model weights.....')
    model.load_weights('weights.best.music3.hdf5')
    print('Model Loaded')
    prediction_output = generate_notes(model,network_input,n_vocab)
    create_midi(prediction_output)

问题如下:

Initiating music generation process.......

---------------------------------------------------------------------------

NameError                                 Traceback (most recent call last)

<ipython-input-24-b97e0091fa1b> in <module>()
----> 1 generate()

<ipython-input-20-27d37a8858b8> in generate()
     13 
     14     network_input = get_inputSequences(notes,n_vocab)
---> 15     model = create_network(normalized_input,n_vocab)
     16     print('Loading Model weights.....')
     17     model.load_weights('weights.best.music3.hdf5')

NameError: name 'normalized_input' is not defined

由于代码不是我的,我不知道这个变量是什么,所以我可以修复它... 我给代码所有者发了电子邮件,但他没有回复。

谢谢

iloveuvm 回答:尝试对音乐数据进行转移学习

我认为实际代码是here

不确定100%,但是很可能是代码错误。假设是 network_input 。所以你改变

network_input = get_inputSequences(notes,pitchnames,n_vocab)
model = create_network(normalized_input,n_vocab)

network_input = get_inputSequences(notes,n_vocab)
model = create_network(network_input,n_vocab)

这会产生以下错误:

Initiating music generation process.......

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-27-b97e0091fa1b> in <module>()
----> 1 generate()

1 frames

<ipython-input-14-866d26da5fd7> in create_network(network_in,n_vocab)
      4     """Create the model architecture"""
      5     model = Sequential()
----> 6     model.add(LSTM(128,input_shape=network_in.shape[1:],return_sequences=True))
      7     model.add(Dropout(0.2))
      8     model.add(LSTM(128,return_sequences=True))

AttributeError: 'list' object has no attribute 'shape'

好吧,如果您查看

中的代码
In [7]: def prepare_sequences(notes,n_vocab):

您会看到到numpy数组的转换:

network_input = np.reshape(network_input,(n_patterns,sequence_length,1))

您应该执行类似于get_inputSequences的操作,以便返回numpy数组,而不是常规的python列表。但是代码看起来很陈旧,因此即使您修复了该错误,也可能会遇到意外的结果,因此最好在github下进行查找。另外,您需要修复并确保获得良好的结果,否则,您需要参与代码。

本文链接:https://www.f2er.com/3089629.html

大家都在问