What is correct shape of input to the LSTM when concatenating features of two different models?

lola1: <p>Hello,</p>
<p>I am having two different, already trained models for video classification, where one model takes keypoints as input, and another model takes video frames as input.</p>
<p>I want to concatenate their features and then pass concatenated vector to the LSTM.</p>
<p>I am little bit confused if my concatenation is correct and how should input to the LSTM look like. At the moment I have the following:</p>
<p>Model A has output <code>[128, 256] = [batch size, num of features]</code><br>
Model B has output <code>[128, 122 880] = [batch size, num of features]</code><br>
After concatenation I have: <code>[128, 123 136]</code></p>
<p>Since LSTM expects input of shape <code>[batch_size x seq_len x input_size]</code> I used:</p>
<pre><code class="lang-auto">x = x.unsqueeze(1) #[128, 1, 123 136]
</code></pre>
<p>But then LSTM does not make sense, since I have no time dimension or? Is this approach correct?</p>
<p>Thanks!</p>

ptrblck: <p>Indeed none of the outputs contain a temporal dimension so it seems both models reduced it in their forward method assuming the original inputs to them still contained the temporal information. Could you thus explain the architecture of <code>modelA</code> and <code>modelB</code> and check if keeping the temporal dimension would make sense?</p>

lola1: <p>Model A is a simple 1D CNN model that takes keypoints as data input. Model B is pretrained Resnet that takes videos as input.</p>
<p>For 1D CNN with keypoints as input data I printed the change of shape during forward:</p>
<pre><code class="lang-auto">torch.Size([512, 51, 45]) # input data [batch size, num of features, num of frames = time dimension]
torch.Size([512, 51, 45])
torch.Size([512, 64, 43])
torch.Size([512, 64, 43])
torch.Size([512, 64, 43])
torch.Size([512, 128, 20])
torch.Size([512, 128, 20])
torch.Size([512, 128, 20])
torch.Size([512, 256, 8])
torch.Size([512, 256, 8])
torch.Size([512, 256, 8])
torch.Size([512, 8, 256])
torch.Size([512, 512])
torch.Size([512, 512])
torch.Size([512, 256]) # -&gt; I took this model up to this point 
torch.Size([512, 8]) 
</code></pre>
<p>So I am assuming, that I should take the model from the “point” where time dimension is stil there or?</p>
<p>But if another model takes videos as files, and shapes look little bit different… can I still simply concatenate them or?</p>

lola1: <p>Here also my model B, input data <code>[batch size, num of channels, num of frames, height, width]</code></p>
<p>while the last few rows of the model (withotu fc layer) are:</p>
<pre><code class="lang-auto">        ResStage-193       [-1, 2048, 22, 8, 8]               0
       AvgPool3d-194       [-1, 2048, 15, 2, 2]               0
         Dropout-195       [-1, 2048, 15, 2, 2]               0 #[batch, num of features, num of frames, height, width]
 ResNetBasicHead-196               [-1, 122880]               0
             Net-197               [-1, 122880]               0
</code></pre>
<p>So when I retain time dimension I am having the following outputs from both models:</p>
<pre><code class="lang-auto">[128, 256, 8]                  #[batch, num of features, num of frames
[128, 2048, 15, 2, 2]      #[batch, num of features, num of frames, height, width]
</code></pre>
<p>How can i concatenate them?</p>