hi, I want to apply 1d convolution on this input data of (128, 64). But, I am finding an error, indeed I provided the input of shape (1, 128, 64) to CNN model. Can you help me to fix?
import torch
import torch.nn as nn
Define our input data (128 samples, each with a sequence of 64 features)
input_data = torch.randn(128, 64)
input_data1 = input_data.unsqueeze(0)
print(input_data.shape)
Define the 1D CNN model
conv1d = nn.Conv1d(in_channels=64, out_channels=32, kernel_size=3)
output = conv1d(input_data1)
print(output.shape)
print(output.unsqueeze(0).shape)
RuntimeError Traceback (most recent call last)
in <cell line: 13>()
11
12
—> 13 output = conv1d(input_data)
14 # Apply the convolution to the input data
15 #output = conv1d(input_data.unsqueeze(0)) # Add a batch dimension with .unsqueeze(0)
3 frames
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight, bias)
304 weight, bias, self.stride,
305 _single(0), self.dilation, self.groups)
→ 306 return F.conv1d(input, weight, bias, self.stride,
307 self.padding, self.dilation, self.groups)
308
RuntimeError: Given groups=1, weight of size [32, 64, 3], expected input[1, 128, 64] to have 64 channels, but got 128 channels instead