繁体   English   中英

Keras LSTM 用序列预测

[英]Keras LSTM predict with sequence

我做了一个 Keras LSTM Model。 但我的问题是,使用我的 input_shape [800, 200, 48] 我预测了一个形状为 [800, 200, 48] 的 output。

我只需要预测没有任何序列的 800x48 标签。

在此处输入图像描述

输入:800 个样本,200 个时间步长,每个时间步长 48 个特征

需要的 Output 是:800 个样本,每个 time_step 48 个特征

我希望有人对此有解决方案!

代码:

from keras.models import Sequential
from keras.layers import Dense, LSTM
from keras.layers import Dropout


model = Sequential()
        

def addInputLayer(units, shape, dropout):
    model.add(LSTM(input_shape=shape, units=units, use_bias=True, unit_forget_bias=True, return_sequences=True))
    model.add(Dropout(dropout))
        
        
def addHiddenLayer(anz, units, dropout):
    for i in range(anz):
        model.add(LSTM(units=units, use_bias=True, unit_forget_bias=True, return_sequences=True))
        model.add(Dropout(dropout))
            
            
def addOutputLayer(units):
    model.add(Dense(units=units))
    
    
def compLstm(optimizer, loss_function):
    model.compile(optimizer=optimizer, loss=loss_function)
    
    
def konfigure(feature, label, epochs, validationFeature, validationLabel, batch_size):
    history = model.fit(feature, label, epochs=epochs, validation_data=(validationFeature, validationLabel), batch_size=batch_size, verbose=2)
    return history


def predict(test):
    predictions = model.predict(test)
    return predictions

为此,最后一个LSTM层的参数return_sequences应该是False 由于您使用的是循环,请尝试这样的事情。 在这里,除了最后一个循环迭代之外, return_sequences将是True

import tensorflow as tf

model = tf.keras.Sequential()

anz = 8

for i in range(anz):
    model.add(tf.keras.layers.LSTM(units=200, return_sequences=i != anz - 1))

model.add(tf.keras.layers.Dense(48, activation='softmax'))

model.build(input_shape=(None, 200, 48))

model.summary()
Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_38 (LSTM)               (None, 200, 200)          199200    
_________________________________________________________________
lstm_39 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_40 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_41 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_42 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_43 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_44 (LSTM)               (None, 200, 200)          320800    
_________________________________________________________________
lstm_45 (LSTM)               (None, 200)               320800    
_________________________________________________________________
dense_4 (Dense)              (None, 48)                9648      
=================================================================
Total params: 2,454,448
Trainable params: 2,454,448
Non-trainable params: 0
_________________________________________________________________

暂无
暂无

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

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