How to build multiple input from multiple network to finally give one output

Raj_Roy: <p>I wanted to build a network that takes 1D features and 2D features and provides them as input in the respective networks (lets says one network with 1d conv and another with 2dconv) but then they are finally combined to give one output. I do not know how to implement it, can you guys give me some ideas?<br>
Thanks in advance</p>

ptrblck: <p>Assuming you have created both models, which accept the features with different dimensions, you could concatenate their outputs if their shapes allow to do so.<br>
Here is a simple example:</p>
<pre><code class="lang-python">class ModelA(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv1d(1, 1, 1)
        self.lin = nn.Linear(10, 10)
        
    def forward(self, x):
        x = self.conv(x)
        x = x.view(x.size(0), -1)
        x = self.lin(x)
        return x
    
class ModelB(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(1, 1, 1)
        self.lin = nn.Linear(10, 10)
        
    def forward(self, x):
        x = self.conv(x)
        x = x.view(x.size(0), -1)
        x = self.lin(x)
        return x

modelA = ModelA()
modelB = ModelB()
xA = torch.randn(1, 1, 10)
xB = torch.randn(1, 1, 5, 2)

outA = modelA(xA)
outB = modelB(xB)
out = torch.cat((outA, outB), dim=1)
print(out.shape)
&gt; torch.Size([1, 20])
</code></pre>

Raj_Roy: <p>Hi,</p>
<p>Thanks a lot for your help. But I think my question was a little misleading in the last part. What I meant was that a network that 2 inputs in 2 different dimensions and produces one result. I did not mean simple concatenation. I have attached a picture for reference, its from a paper. Sorry for misleading question</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/7/67c51cfb91f609e841e02bf469ce7ecf582b2d02.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/67c51cfb91f609e841e02bf469ce7ecf582b2d02" title="bbab038f1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67c51cfb91f609e841e02bf469ce7ecf582b2d02_2_690x315.jpeg" alt="bbab038f1" data-base62-sha1="eNZuxqWr1FqhCmM8B3MuTm777jk" width="690" height="315" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/7/67c51cfb91f609e841e02bf469ce7ecf582b2d02_2_690x315.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/6/7/67c51cfb91f609e841e02bf469ce7ecf582b2d02.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/7/67c51cfb91f609e841e02bf469ce7ecf582b2d02.jpeg 2x" data-dominant-color="E4E8E7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">bbab038f1</span><span class="informations">1000×457 104 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>I’m not familiar with this figure/model, but it seems that features are packed via an “outer concatenation”? Could you describe how it was done, if not through concatenating tensors, please?</p>

Raj_Roy: <p>I am also not very aware of what they did and also I am fairly new to this. But here is an idea of what they did. They extracted 1d feature as suggested on the top part of the image and also extracted the 2d features from the data (feature generation can be done in many way so not a problem). But the intriguing part for me is how these 1d and 2d features can be combined to train one single network (here in this case 2D resnetv2 ) as presented in this picture.</p>
<p>Sincerely<br>
Raj</p>