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)

修改后运行成功。



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值