I am trying to train a PyTorch LSTM model which is defined as:
class RecurrentNet(torch.nn.Module):
def __init__(self, d_in, d_hidden, sequence_length):
super(RecurrentNet, self).__init__()
self.d_in = d_in
self.d_hidden = d_hidden
self.sequence_length = sequence_length
self.lstm = torch.nn.LSTM(input_size=d_in, hidden_size=d_hidden, num_layers=sequence_length)
self.fc = nn.Linear(d_hidden, 1)
def forward(self, x):
out, hidden = self.lstm(x)
y_pred = F.relu(self.fc(out[-1][-1]))
return y_pred
model = RecurrentNet(28, 3, l)
I have prepared my data in the form of batches of len 32, and with each instance having dimensions of 6 x 28, i.e. torch.Size([6, 28]). This means the total input tensor is size torch.Size([32, 6, 28]), with labels size torch.Size([32, 1]).
When I pass a single instance to the untrained model it returns an integer as expected. When I pass the Tensor of 32 intances, it returns:
tensor([0.], grad_fn=<ReluBackward0>)
I would have expect a 32 x 1 output Tensor for this input. Have I missed something when preparing the training data?