Python 3.x 尝试使用音乐数据运行迁移学习

Python 3.x 尝试使用音乐数据运行迁移学习,python-3.x,github,google-colaboratory,Python 3.x,Github,Google Colaboratory,我正在尝试在以下存储库中执行github代码: 错误出现在以下函数中: 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

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

错误出现在以下函数中:

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
启动音乐生成过程。。。。。。。
---------------------------------------------------------------------------
NameError回溯(最近一次呼叫上次)
在()
---->1生成()
在generate()中
13
14网络输入=获取输入序列(音符、音高名称、n音)
--->15模型=创建网络(标准化输入,n\u vocab)
16打印(“加载模型重量…”)
17型号负载重量('weights.best.music3.hdf5')
NameError:未定义名称“规范化\u输入”
因为代码不是我的,我不知道这个变量是什么,所以我可以修复它。。。 我给代码所有者发了电子邮件,但他没有回复


谢谢

我想实际的代码是

不是100%确定,但很可能是代码中的错误。应该是网络输入。所以你改变了

network_input = get_inputSequences(notes, pitchnames, n_vocab)
model = create_network(normalized_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'
您可以看到到numpy数组的转换:

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

您应该执行类似的操作来获取输入序列,以便返回numpy数组,而不是常规的python列表。但是代码看起来很旧,所以即使修复了错误,也可能会产生意外的结果,所以最好在github下解决它。或者,您需要修复并确保获得良好的结果,如果没有,您需要参与到代码中。

我已经使用此选项进行了测试,它也不起作用:(我编辑了你的错误消息…嗯…这很奇怪。我会再次编辑,我有个主意,但最好联系vendorI edited,你可以很容易地修复错误,但你必须确保代码产生正确的结果。这是问题我已经找到了那个家伙,但我还没有得到任何答案!!!看到这个:
In [7]: def prepare_sequences(notes, n_vocab):
network_input = np.reshape(network_input, (n_patterns, sequence_length, 1))