Мой ввод имеет размер:
Training Shape torch.Size([290002, 1, 6]) torch.Size([290002, 1])
Testing Shape torch.Size([74998, 1, 6]) torch.Size([74998, 1])
моя модель:
Код: Выделить всё
class LSTM(nn.Module):
def __init__(self, hidden_dim_LSTM, num_layers_LSTM, hidden1, drop):
super(LSTM, self).__init__()
self.hidden_dim_LSTM = hidden_dim_LSTM
self.num_layers_LSTM = num_layers_LSTM
self.hidden1=hidden1
self.drop=drop
final_output_dim = 1
#self.lstm = nn.LSTM(self.input_dim, self.hidden_dim, self.num_layers, batch_first=True)
self.lstm = nn.LSTM(6, hidden_size=hidden_dim_LSTM, num_layers=num_layers_LSTM, batch_first=True)
self.fc1 = nn.Linear(in_features=hidden_dim_LSTM, out_features=hidden1)
self.drop = nn.Dropout(drop)
self.fc2 = nn.Linear(in_features=hidden1, out_features=final_output_dim)
def forward(self, x):
h_0 = Variable(torch.zeros(self.num_layers_LSTM, x.size(0), self.hidden_dim_LSTM)).requires_grad_().to(device) #hidden state
c_0 = Variable(torch.zeros(self.num_layers_LSTM, x.size(0), self.hidden_dim_LSTM)).requires_grad_().to(device) #internal state
# Propagate input through LSTM
output, (hn, cn) = self.lstm(x, (h_0, c_0)) #lstm with input, hidden, and internal state
hn = hn.view(-1, self.hidden_dim_LSTM) #reshaping the data for Dense layer next
out = F.relu(hn)
out = self.fc1(out)
out = self.drop(out)
out = torch.relu(out)
#out = self.drop(out)
out = self.fc2(out)
return out
RuntimeError: Для непакетного двумерного ввода hx и cx также должны быть двумерными, но имеют (3-D, 3-D) тензоры
в строке: вывод, (hn, cn) = self.lstm(x, (h_0, c_0))
Я благодарен за любую помощь!
Подробнее здесь: https://stackoverflow.com/questions/725 ... ut-got-3-d
Мобильная версия