简体   繁体   English

keras LSTM 输入和 output 形状如何工作?

[英]How do keras LSTM input and output shapes work?

        trainX, trainY, sequence_length=len(train), batch_size=batchTrain
    )
    val=timeseries_dataset_from_array(
        valX, valY, sequence_length=len(val), batch_size=batchVal
    )    
    test=timeseries_dataset_from_array(
        testX, testY, sequence_length=len(test), batch_size=batchTest
    )
    
    return train, val, test

train, val, test = preprocessor()

model=Sequential()
model.add(LSTM(4,return_sequences=True))
model.add(Dense(2,activation='softmax'))
model.compile(optimizer='Adam', loss="mae")
model.fit(train, epochs=200, verbose=2, validation_data=val, shuffle=False)

I'm trying to make an LSTM from time-series data and when I run the above, the loss doesn't change at all.我正在尝试从时间序列数据中制作 LSTM,当我运行上述内容时,损失根本没有改变。 I'm definitely struggling to understand how lstm input/output shapes work.我肯定很难理解 lstm 输入/输出形状是如何工作的。 I've read as much online as I could find, but I can't seem to get the model to learn.我已经尽可能多地在网上阅读,但我似乎无法让 model 学习。 I'm under the impression that the first argument is the dimensionality of the output space.我的印象是第一个参数是 output 空间的维度。 I want the lstm to return the whole sequence to the output function.我希望 lstm 将整个序列返回给 output function。

There are many problems in your model.你的 model 有很多问题。 You final layer is dense with two units and you are using softmax which should be replaced by sigmoid .你的最后一层是密集的两个单位,你正在使用softmax应该被sigmoid替换。 Since you are using softmax , i guess that you are using this model for classification and not regression.由于您使用的是softmax ,我猜您正在使用此 model 进行分类而不是回归。

If you are using a model for classification tasks then you should use BinaryCrossentropy and not MeanAbsoluteError as loss.如果您使用 model 进行分类任务,那么您应该使用BinaryCrossentropy而不是MeanAbsoluteError作为损失。

To answer the question in full detail, you need to post the additional information.要详细回答问题,您需要发布附加信息。 For example: What are you target variables etc.例如:您的目标变量是什么等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM