The start of my model looks like this:
def __init__(self, pretrained=False):
super().__init__()
self.base = nn.ModuleList([])
# Stem layer
self.base.append(ConvLayer(in_channels=4, out_channels=first_ch[0], kernel=3, stride=2))
self.base.append(ConvLayer(in_channels=first_ch[0], out_channels=first_ch[1], kernel=3))
self.base.append(nn.MaxPool2d(kernel_size=2, stride=2))
# Rest of model definition goes here
self.base.append(...)
def forward(self, x):
out_branch =[]
for i in range(len(self.base)-1):
x = self.base[i](x)
out_branch.append(x)
return out_branch
Notice that it takes 4 channels as input in the first conv layer. This input is an RGB tensor (first 3 channels) with an extra channel added by the data loader. I want to change this so I can first split the in_channels into 3 and 1 so that I can have 2 stems: one stem for the RGB channels, and a second stem for the 4th channel. I will then concat the output of the single channel stem at some later point in the network. What might be the best way to do this?