How to input the tensor from CNN to RNN

When I was dealing a model that is 1-d CNN + RNN, I found that the size of output from CNN is (batch_size, out_channels, features) where the features are time series.
However, the RNN requires the size of input is (batch_size, time_step, “features”). So I can’t put the CNN output into RNN neural network directly. Because the “features” in RNN is out_channels in CNN and I need to reshape it.

So, is there any function can solve this format problem? With GPU, can I use a for loop to deal with it?

Thank you!

You could permute the activation and pass the right shape via:

print(out.shape) # [batch_size, out_channels, seq_len]
out = out.permute(0, 2, 1) # [batch_size, seq_len, out_channels]

This would shift the temporal dimension to dim1 and the output channels to dim2.

It works! Thank you very much, bro!