0

Can anyone help me to understand when I use conv1d and then a linear layer, What will be the inputs of the linear layer? How to calculate how many input features should I have to pass in pytorch

1 Answer 1

1

In Pytorch, Linear layers operate using only the last dimension of the input tensor: [*features_in] -> [*,features_out].

However, Conv1D layers consider the last 2 dimensions of the input tensor: [batches,channels_in, length_in] -> [batches,channels_out, length_out].

Therefore, if no pre-processing is used, Linear layers will only work with the signals defined for every channel, i.e., [batches,channels_in,features_in] -> [batches,channels_in,features_out]. This behavior is rarely desired, so people usually flatten tensors before passing them to a Linear layer. For example, it's common to use Linear(x.view(n_batches,-1)).

The behavior you need depends on the details of your application. Good luck,

Sources:

https://pytorch.org/docs/stable/generated/torch.nn.Conv1d.html (Conv1d) https://pytorch.org/docs/stable/generated/torch.nn.Linear.html (Linear)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.