【问题标题】:Trying to run a transfer learning with music data尝试使用音乐数据进行迁移学习
【发布时间】:2020-03-12 12:18:25
【问题描述】:

我正在尝试在以下存储库中执行 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, pitchnames, 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, pitchnames, 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

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

谢谢

【问题讨论】:

    标签: python-3.x github google-colaboratory


    【解决方案1】:

    我假设实际代码是here

    不是 100% 肯定,但很可能是代码中的错误。应该是 network_input。所以你改变了

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

    network_input = get_inputSequences(notes, pitchnames, 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 下弄清楚。或者,您需要修复并确保获得良好的结果,否则您需要参与代码。

    【讨论】:

    • 我已经用这个选项测试过,它也不起作用:(
    • 我编辑了你的错误信息......嗯......这很奇怪。我会再编辑,我有一个想法,但最好联系供应商
    • 我编辑了,您可以轻松修复错误,但您必须确保代码产生正确的结果
    • 这个问题我已经和那个人联系过了,但我没有得到任何答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2023-01-18
    • 2018-05-31
    • 2016-05-18
    • 2018-05-30
    • 1970-01-01
    • 2019-11-08
    相关资源
    最近更新 更多