I use lstm from pytorch in my code to predict time series. while i write this code
class LSTM_model(nn.Module):
def __init__(self, input_size, output_size, hidden_size,num_layers,dropout):
super(LSTM_model,self).__init__()
self.input_size = input_size
self.hidden_size = hidden_size
self.seq_len = seq_len
self.num_layers = num_layers
self.dropout = dropout
self.output_size = output_size
# self.lstm=nn.LSTM(self.input_dim, self.hidden_dim, self.num_layers)
self.lstm = nn.LSTM(self.input_size, self.hidden_size,self.num_layers , self.dropout, batch_first=True)
self.fc= nn.Linear(self.hidden_size , self.output_size)
def forward(self, x , hidden):
x, hidden= self.lstm(x,hidden)
x = self.fc(x)
return x,hidden
I got error from x,hidden = self.lstm(x.hidden) about the internal of that function.
the error message written below
i
python-input-59-c75cf1303610> in forward(self, x, hidden)
15
16 def forward(self, x , hidden):
---> 17 x, hidden= self.lstm(x,hidden)
18 x = self.fc(x)
19 return x,hidden
D:\Anaconda\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
725 result = self._slow_forward(*input, **kwargs)
726 else:
--> 727 result = self.forward(*input, **kwargs)
728 for hook in itertools.chain(
729 _global_forward_hooks.values(),
D:\Anaconda\lib\site-packages\torch\nn\modules\rnn.py in forward(self, input, hx)
579 self.check_forward_args(input, hx, batch_sizes)
580 if batch_sizes is None:
--> 581 result = _VF.lstm(input, hx, self._flat_weights, self.bias, self.num_layers,
582 self.dropout, self.training, self.bidirectional, self.batch_first)
583 else:
TypeError: lstm() received an invalid combination of arguments - got (Tensor, tuple, list, int, int, float, bool, bool, bool), but expected one of:
* (Tensor data, Tensor batch_sizes, tuple of Tensors hx, tuple of Tensors params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional)
didn't match because some of the arguments have invalid types: (Tensor, !tuple!, !list!, !int!, !int!, !float!, !bool!, bool, bool)
* (Tensor input, tuple of Tensors hx, tuple of Tensors params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional, bool batch_first)
didn't match because some of the arguments have invalid types: (Tensor, !tuple!, !list!, !int!, int, float, bool, bool, bool)
Can someone help me please