spdin / time-series-prediction-lstm-pytorch

Time Series Prediction with LSTM Using PyTorch
209 stars 37 forks source link

lstm input is wrong #3

Open davide-burba opened 4 years ago

davide-burba commented 4 years ago

Inside LSTM class:

change this:

ula, (h_out, _) = self.lstm(x, (h_0, c_0))
h_out = h_out.view(-1, self.hidden_size)

to this:

h_out, _ = self.lstm(x, (h_0, c_0))
h_out = h_out.view(-1,x.size(1),self.hidden_size)[-1] 

also, when you train/predict the model, use dataX.transpose(0,1) as input

Check https://pytorch.org/docs/stable/nn.html?highlight=lstm#torch.nn.LSTM for reference on input/output formatting for LSTM layer

Now you can use multiple layers.