title: Match CNN output with LSTM input dimensions (Pytorch)
body: <p>I would like to build a hybrid CNN-LSTM model and have training samples of the following shape: (21,6000)</p>
  <p>I built the CNN with the following layers</p>
  <pre><code>from torchsummary import summary
  summary(model, (21, 6000))
  </code></pre>
  <p>returns
  <a href="https://i.stack.imgur.com/t0aFs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t0aFs.png" alt="enter image description here" /></a></p>
  <p>I would like to use the output of the CNN model (the output from the layer before softmax, for example) and use it as an input for the LSTM. To align the CNN output with the LSTM input, I looked into examples using <code>padding=same</code> and <code>permute</code>.
  Could you give me a hint on what input shape the LSTM would expect here and how I could transform the output shape of the CNN to match that input shape?</p>
  <p>As mentioned here <a href="https://discuss.pytorch.org/t/cnn-with-lstm-input-shapes/86910/9" rel="nofollow noreferrer">https://discuss.pytorch.org/t/cnn-with-lstm-input-shapes/86910/9</a>, the following gets the required input shape of the LSTM</p>
  <pre><code>x = torch.randn(1, 2, 394, 1)
  x = x.view(x.size(0), -1, x.size(3)) # [batch_size, features=channels*height, seq_len=width]
  x = x.permute(2, 0, 1) # [seq_len, batch_size, features]
  x.size()
  </code></pre>
  <p>returns</p>
  <pre><code>torch.Size([1, 1, 788])
  </code></pre>