Skip to content

How to apply a nn.Module (i.e. CNN) across an axis (i.e. Video input) in a parallelizable way #6135

Discussion options

You must be logged in to vote

You can simply convert your (batch_size, seq_len, channel, height, width) tensor into an (batch_size*seq_len, channel, height, width) tensor, run your model and then reshape your output back:

batch_size, seq_len, channel, height, width = 5, 10, 3, 28, 28 # just random picked
input = torch.randn(batch_size, seq_len, channel, height, width)
input = input.reshape(batch_size * seq_len, channel, height, width)
output = model(input) 
# split the batch dimension back into the original batch size and sequence length
output = output.reshape(batch_size, seq_len, *output.shape[1:])

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@seunggs
Comment options

Answer selected by seunggs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants