CNTK-106 Part A:ValueError

教材网址:https://cntk.ai/pythondocs/CNTK_106A_LSTM_Timeseries_with_Simulated_Data.html
编程系统:windows7
开发语言: python2.7
      在运行CNTK-106 PartA出现了错误:
Traceback (most recent calllast):
File"E:\ProgramLib\Python\CNTK\CNTK-106-PartA-LSTM.py",line 171, in trainer.train_minibatch({x:x1, l: y1})
File"C:\Python27\lib\site-packages\cntk\train\trainer.py",line 184, in
train_minibatch device) File"C:\Python27\lib\site-packages\cntk\cntk_py.py",line 2856, in
train_minibatch
return _cntk_py.Trainer_train_minibatch(self,*args)
ValueError: The trailing dimensions of the Valueshape '[100]' do not match the Variable 'Input('y', [#], [1])'shape '[1]'.

解决方法:
1.原因:输入的Y,数据格式错误,应该变形成X的格式。
X:
[[0.02000067]
[0.0299985 ]
[0.03999333]
[0.04998416]
[0.05997 ]]
Y: [0.08988751 0.099843370.10978924]
应该把Y变成形如:
[ [0.08988751]
[0.09984337]
[0.10978924]]

2.修改的代码:
def generate_data(fct, x, time_steps,time_shift):
"""
generate sequences to feed to rnn for fct(x)
"""
    data = fct(x)
    if not isinstance(data, pd.DataFrame):
    data = pd.DataFrame(dict(a = data[0:len(data) - time_shift],
                                               b = data[time_shift:]))  
    rnn_x = []
    for i in range(len(data) - time_steps + 1):
        rnn_x.append(data['a'].iloc[i: i + time_steps].as_matrix())
        rnn_x = np.array(rnn_x)

    # Reshape or rearrange the data from row to columns
    # to be compatible with the input needed by the LSTM model
#which expects 1 floatper time point in a given batch
    rnn_x = rnn_x.reshape(rnn_x.shape + (1,))

    rnn_y = data['b'].values
    rnn_y = rnn_y[time_steps - 1 :]
    rnn_y = rnn_y.reshape(rnn_y.shape + (1,))  # 增加该行代码,将Y变成X样式

    return split_data(rnn_x), split_data(rnn_y)

修改后运行成功。



你可能感兴趣的:(CNTK,CNTK)