Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

python - 如何为LSTM模型创建输出图层?(How to create layer for output for LSTM model?)

i'm still learning in LSTM classification.

(我仍在学习LSTM分类。)

my input dataset is (2386, 3) where (n_rows, n_predictive)
my output dataset is (2386, 7) where (n_rows, n_label)

my input windows size is (2369, 12, 3) where (n_sample, n_input, n_predictive)
my output windows size is (2369, 6, 7) where (n_sample, n_output, n_label)

using this code
        model = Sequential()
        model.add(LSTM(300, return_sequences=True, input_shape=(n_input, n_predictive)))
        model.add(TimeDistributed(Dense(n_label)))
        model.add(Activation('softmax'))
        model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])

obtain this layer
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
cu_dnnlstm_93 (CuDNNLSTM)    (None, 12, 300)           363600    
_________________________________________________________________
time_distributed_14 (TimeDis (None, 12, 7)             2107      
_________________________________________________________________
activation_13 (Activation)   (None, 12, 7)             0         
=================================================================

and its error

(及其错误)

 Error when checking target: expected activation_13 to have shape (12, 7) but got array with shape (6, 7)

I try to create the layer but I'm unable to create layer with (None, 6, 7) , do you guys have any suggestion on how I can create layer with (None, 6, 7)?

(我尝试创建图层,但是无法使用(None,6,7)创建图层,你们对我如何使用(None,6,7)创建图层有任何建议吗?)

update (更新)

when I try to fit the model with the same input and output windows, as below

(当我尝试使用相同的输入和输出窗口来拟合模型时,如下所示)

input windows size is (2369, 12, 3)
output windows size is (2369, 12, 7)

the model does not have error BUT, I found out that the label prediction give 12 step late than the actual.

(该模型没有错误,但我发现标签预测比实际延迟了12步。)

when I use different windows size for example

(例如,当我使用其他窗口大小时)

input windows size is (2369, 6, 3)
output windows size is (2369, 6, 7)

I found out that the label prediction give 6 step late than the actual.

(我发现标签预测比实际延迟了6个步骤。)

I already checked windows split sequence function where I follow this code from this blog https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/

(我已经检查了Windows拆分序列功能,在这里我遵循此博客https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/中的代码)

the windows split is just working fine.

(窗户分开工作正常。)

But it seem that the LSTM model working weird.

(但是似乎LSTM模型工作异常。)

Does the LSTM model for classification are affected with the windows size?

(LSTM分类模型是否会受到窗口大小的影响?)

  ask by lemon93 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...