A single model that contains two separate ResNet models(without FC , the FC is after the contact )

adam_kossemtini: <p>I have a single model (<code>Net</code> ) that contains two separate ResNet models(without FC , the FC is after the contact )<br>
the input of net1 are images with resolution (51,50,4) and the input of net2 are images with resolution (15,15,40)<br>
import torch<br>
import torch.nn as nn</p>
<p>class block(nn.Module):<br>
def <strong>init</strong>(<br>
self, in_channels, intermediate_channels, identity_downsample=None, stride=1<br>
):<br>
super(block, self).<strong>init</strong>()<br>
self.expansion = 4<br>
self.conv1 = nn.Conv2d(<br>
in_channels, intermediate_channels, kernel_size=1, stride=1, padding=0, bias=False<br>
)<br>
self.bn1 = nn.BatchNorm2d(intermediate_channels)<br>
self.conv2 = nn.Conv2d(<br>
intermediate_channels,<br>
intermediate_channels,<br>
kernel_size=3,<br>
stride=stride,<br>
padding=1,<br>
bias=False<br>
)<br>
self.bn2 = nn.BatchNorm2d(intermediate_channels)<br>
self.conv3 = nn.Conv2d(<br>
intermediate_channels,<br>
intermediate_channels * self.expansion,<br>
kernel_size=1,<br>
stride=1,<br>
padding=0,<br>
bias=False<br>
)<br>
self.bn3 = nn.BatchNorm2d(intermediate_channels * self.expansion)<br>
self.relu = nn.ReLU()<br>
self.identity_downsample = identity_downsample<br>
self.stride = stride</p>
<pre><code>def forward(self, x):
    identity = x.clone()

    x = self.conv1(x)
    x = self.bn1(x)
    x = self.relu(x)
    x = self.conv2(x)
    x = self.bn2(x)
    x = self.relu(x)
    x = self.conv3(x)
    x = self.bn3(x)

    if self.identity_downsample is not None:
        identity = self.identity_downsample(identity)

    x += identity
    x = self.relu(x)
    return x
</code></pre>
<p>class ResNet(nn.Module):<br>
def <strong>init</strong>(self, block, layers, image_channels, num_classes):<br>
super(ResNet, self).<strong>init</strong>()<br>
self.expansion = 4<br>
self.in_channels = 64<br>
self.conv1 = nn.Conv2d(image_channels, 64, kernel_size=1, stride=1, padding=0, bias=False)<br>
self.bn1 = nn.BatchNorm2d(64)<br>
self.relu = nn.ReLU()<br>
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)</p>
<pre><code>    # Essentially the entire ResNet architecture are in these 4 lines below
    self.layer1 = self._make_layer(
        block, layers[0], intermediate_channels=64, stride=1
    )
    self.layer2 = self._make_layer(
        block, layers[1], intermediate_channels=128, stride=2
    )
    self.layer3 = self._make_layer(
        block, layers[2], intermediate_channels=128, stride=2
    )
    self.layer4 = self._make_layer(
        block, layers[3], intermediate_channels=128, stride=2
    )
    self.layer5 = self._make_layer(
        block, layers[4], intermediate_channels=256, stride=2
    )
    self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        
def forward(self, x):
    x = self.conv1(x)
    x = self.bn1(x)
    x = self.relu(x)
    x = self.maxpool(x)
    x = self.layer1(x)
    x = self.layer2(x)
    x = self.layer3(x)
    x = self.layer4(x)
    x = self.layer5(x)

    x = self.avgpool(x)
    x = x.reshape(x.shape[0], -1)


    return x

def _make_layer(self, block, num_residual_blocks, intermediate_channels, stride):
    identity_downsample = None
    layers = []

    # Either if we half the input space for ex, 56x56 -&gt; 28x28 (stride=2), or channels changes
    # we need to adapt the Identity (skip connection) so it will be able to be added
    # to the layer that's ahead
    if stride != 1 or self.in_channels != intermediate_channels * 4:
        identity_downsample = nn.Sequential(
            nn.Conv2d(
                self.in_channels,
                intermediate_channels * 4,
                kernel_size=1,
                stride=stride,
                bias=False
            ),
            nn.BatchNorm2d(intermediate_channels * 4),
        )

    layers.append(
        block(self.in_channels, intermediate_channels, identity_downsample, stride)
    )

    # The expansion size is always 4 for ResNet 50,101,152
    self.in_channels = intermediate_channels * 4

    # For example for first resnet layer: 256 will be mapped to 64 as intermediate layer,
    # then finally back to 256. Hence no identity downsample is needed, since stride = 1,
    # and also same amount of channels.
    for i in range(num_residual_blocks - 1):
        layers.append(block(self.in_channels, intermediate_channels))

    return nn.Sequential(*layers)
</code></pre>
<p>def ResNet50(img_channel=4, num_classes=2):<br>
return ResNet(block, [3, 4,6, 3,3], img_channel, num_classes)</p>
<p>import torch.optim as optim<br>
net1 = ResNet50(img_channel=4, num_classes=2)</p>
<p>when i turn this model the accuracy is 0,114%<br>
who can help me to find the problem in my code ? thank you</p>