If we use LSTMCell from torch:
The initial hidden and cell layers should be CONSTANT (from the first time you run the program) and saved right? Like random seeds?
class Model: def __init__(...): self.lstm_h0 = torch.randn(1, hidden_size, requires_grad=False) self.lstm_c0 = torch.randn(1, hidden_size, requires_grad=False)
Let's say our problem is we want to count the number of balls in a video and run an LSTM over each frame of the video.
self.lstm_cell = LSTMCell(...) for i in range(num_frames): h, c = self.lstm_cell(frame[i], (h, c))
The final output embedding we use (to then project into a scalar 'ball count') is the final "h" hidden output, right?
I have (N, nB, nE) dimensional data, call it "my_data". N is the batch dimension, nB is an object dimension, and nE is an embedding dimension. I want to use LSTM to perform dimensionality reduction over nB.
for i in range(nB): h, c = self.lstm_cell(my_data[:, i, :], (h, c))
Is this the correct way to do it?