I have a data of 2 temporal series of 18 points each one. So I organized in a matrix of 18 rows and 2 columns (with 180 samples to classify in 2 classes - activated and non-activated).
So, I want to do a CNN with this data, my kernel walks in one direction, along the lines (temporal). Examples of the figure attached.
In my code, I don't know how channels I have, in comparison to RGB with 3 channels. And don't know the input sizes of the layers, and how to calculate to know the fully connected layer.
I need to use conv1d ? conv2d? conv3d ? Based on Understand conv 1D 2D 3D, I have 2D inputs and I want to do 1D convolution (because I move my kernel in one direction), is it correct ?
How I pass the kernel size (3,2) for example?
My data is in this form, after using DataLoader with batch_size= 4:
print(data.shape, label.shape)
torch.Size([4, 2, 18]) torch.Size([4, 1])
My Convolutional Model is:
OBS: I just put any number of input/output size.
# Creating our CNN Model -> 1D convolutional with 2D input (HbO, HbR)
class ConvModel(nn.Module):
def __init__(self):
super(ConvModel, self).__init__()
self.conv1 = nn.Conv1d(in_channels=1, out_channels= 18, kernel_size=3, stride = 1)
# I dont know the in/out channels of the first conv
self.maxpool = nn.MaxPool1d(kernel_size=3, stride=3)
self.conv2 = nn.Conv1d(18, 32, kernel_size=3)
self.fc1 = nn.Linear(200, 100) #What I put in/out here ?
self.fc2 = nn.Linear(100, 50)
self.fc3 = nn.Linear(50, 2)
def forward(self, x):
x = F.relu(self.mp(self.conv1(x)))
x = self.maxpool(x)
x = F.relu(self.mp(self.conv2(x)))
x = self.maxpool(x)
x = x.view(-1, ??) # flatten the tensor, which number here ?
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x