I would like to build a 1DConvNet (2 channels) with residual connections but I don’t know how to add residual blocks to the model. All examples I found online describe residual blocks and their implementation using image data (2D convolutions). Here is my simple Conv1D model so far.
import torch import torch.nn as nn import torch.nn.functional as F class SimpleNet(nn.Module): def __init__(self): super(SimpleNet, self).__init__() self.conv1 = nn.Conv1d(2, 32, kernel_size=1) self.conv2 = nn.Conv1d(32, 32, 3) self.conv3 = nn.Conv1d(32, 64, 3) self.conv4 = nn.Conv1d(64, 64, 3) self.avg_pool = nn.AdaptiveAvgPool1d(1) self.linear = nn.Linear(64, 3) def forward(self, x): x = F.max_pool1d(F.relu(self.conv1(x)), kernel_size=1, stride=1) x = F.max_pool1d(F.relu(self.conv2(x)), kernel_size=2, stride=2) x = F.max_pool1d(F.relu(self.conv3(x)), kernel_size=2, stride=2) x = F.max_pool1d(F.relu(self.conv4(x)), kernel_size=2, stride=2) x = self.avg_pool(x) x = x.view(x.size(0), -1) x = self.linear(x) return x
Thanks in advance for your help!