Input form of conv1d

please, I have an input of the shape

[1, 2, 20, 135]

and I have a model

Net = torch.nn.Conv1d(in_channels=2, out_channels=8, kernel_size=(20, 1), stride=1, bias=True)

when I execute this line

Net(input)

I get the following error:

RuntimeError: Expected 2D (unbatched) or 3D (batched) input to conv1d, but got input of size: [1, 2, 20, 135]

how I can solve this problem? and thank you

nn.Conv1d expects a 3-dimensional input in the shape [batch_size, channels, seq_len] while you are using a 4-dimensional input.
If your input represents [batch_size, channels, height, width] use nn.Conv2d or manipulate the shape to create a 3-dimensional tensor (e.g. by flattening the spatial dimensions into a single one, if this fits your use case).

1 Like