I am getting confused about the input shape to GRU layer.
I have a batch of 128 images and I extracted 9 features from each images.
So now my shape is (1,128,9).
This is the GRU layer
gru=torch.nn.GRU(input_size=128,hidden_size=8,batch_first=True)
Question 1: Is the input_size=128 correctly defined?
Here is the code of forward function
def forward(features):
features=features.permute(0,2,1)#[1, 9, 128]
x2,_=self.gru(features)
Question 2: Is the `code in forward function is correctly defined?
Thanks
No,
input_sizeis not correctly defined. Here,input_sizemeans the number of features in a single input vector of the sequence. The input to the GRU is a sequence of vectors, each input being a 1-D tensor of lengthinput_size. In case of batched input, the input to GRU is a batch of sequence of vectors, so the shape should be(batch_size, sequence_length, input_size)whenbatch_first=Trueotherwise the expected shape is(sequence_length, batch_size, input_size)whenbatch_first=Falseoutput
Using
batch_first=Falseoutput