Multilayer fusion

hi i want to fuse features from certain layers in network say resnet 50 and provide that as input to subsequent layers how do i do it.

  1. Extraction of features from desired layers
  2. concat it and give that as input.

Please provide forward method for such kind of fusion…

class Model(nn.Module):
    def __init__(self):
        self.linear1 = nn.Linear(5, 5)
        self.linear2 = nn.Linear(5, 5)
        self.linear3 = nn.Linear(5, 5)
    def forward(self, x):
        x1 = self.linear1(x)
        x2 = self.linear2(x1)
        x3 = self.linear3(x2)
        # Fuse output from linear1 with output of linear3
        x =, x3), 0)
        return x
model = Model()
x = torch.rand(2, 5)
output = model(x)
torch.Size([2, 5])
torch.Size([2, 5])
torch.Size([4, 5])

If suppose Last layer was to get input of 10 instead of 5…Linear(10,5)
how would the concat statement look like,