How to set sample input size with different width in different channels to Conv1d in pytorch

I’m new at deep learning, and I’m writing a 1D CNN model to train my dataset. Each data in the dataset contains three channels: (raw_data, sex, age) . The sample rate of raw_data is 50Hz, and window size is 2 seconds, which means 100 samples in one data. So my data will look like this ([1,2,3,4,...,100],[1],[20]) where [1] means sex and [20] means age.

Now I want to put this data into my 1D CNN model. I know that nn.Conv1d(batch_size, channel, width) . If width in all channels are the same, there is no problem. But in my case, raw_data contains 100 elements, sex and age only contain 1 element. How can I put this into my Conv1d layer?

Any help would be appreciated. Thank you!

If I understand the use case correctly, raw_data is some kind of temporal signal, while sex and age are some independent features.
I would try to apply the conv layer on the temporal signal alone, use pass the other features e.g. to a linear layer, and concatenate the outputs afterwards.
Alternatively, you could of course try to add sex and age to the temporal signal, but I’m not sure, if your conv layer will capture the information accordingly.

2 Likes