class Block(nn.Module):
    def __init__(self,in_channels,out_channels,downsample = None , stride = 1):
        super(Block,self).__init__()
        self.expansion = 4
        self.conv1  = nn.Conv2d(in_channels,out_channels,kernel_size=7,padding=3,stride=1)
        self.bn1 = nn.BatchNorm2d(out_channels)
        self.conv2  = nn.Conv2d(out_channels,out_channels,kernel_size=5,padding=2,stride=stride)
        self.bn2 = nn.BatchNorm2d(out_channels)
        self.conv3  = nn.Conv2d(out_channels,out_channels*self.expansion,kernel_size=1,padding=0,stride=1)
        self.bn3 = nn.BatchNorm2d(out_channels*self.expansion)
        self.elu = nn.ELU()
        self.identity_downsample = downsample

    def forward(self,x):
        
        out = self.conv1(x)
        out = self.bn1(out)
        out = self.elu(out)
        out = self.conv2(out)
        out = self.bn2(out)
        out = self.elu(out)
        out = self.conv3(out)
        out = self.bn3(out)
        # out = self.elu(out)
        # print(x.shape)
        if self.identity_downsample is not None:
            x = self.identity_downsample(x)
        # print(out.shape,x.shape)
        out = torch.add(out,x)
        out = self.elu(out)

        return out

class Resnet(nn.Module):

    
    def __init__(self, block, num_blocks, image_channels, num_classes):
        super(Resnet,self).__init__()
        self.in_channels = 64
        self.conv1 = nn.Conv2d(image_channels,self.in_channels,kernel_size = 7, stride = 2, padding = 3)
        self.bn1 = nn.BatchNorm2d(self.in_channels)
        self.elu = nn.ELU()
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = self.make_layer(
            Block, num_blocks[0], out_channels=self.in_channels, stride=1
        )

        
        self.layer2 = self.make_layer(
            Block, num_blocks[1], out_channels=128, stride=2
        )
        

        self.layer3 = self.make_layer(
            Block, num_blocks[2], out_channels=256, stride=2
        )


        self.layer4 = self.make_layer(
            Block, num_blocks[3], out_channels=512, stride=2
        )


        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.fc1 = nn.Linear(512 * 4, 512)
        self.fc2 = nn.Linear(512,num_classes)

    def forward(self, x):

        x = self.conv1(x)
        x = self.bn1(x)
        x = self.elu(x)
        x = self.maxpool(x)
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.drop4(x)
        x = self.avgpool(x)
        x = x.reshape(x.shape[0], -1)
        x = self.fc1(x)
        x = self.fc2(x)

        return x
    

    def make_layer(self,Block,num_blocks,out_channels,stride):
        identity_downsample = None
        layers = []

        if stride != 1 or self.in_channels != out_channels * 4:
            identity_downsample = nn.Sequential(
                nn.Conv2d(
                    self.in_channels,
                    out_channels * 4,
                    kernel_size=1,
                    stride=stride,
                    bias=False
                ),
                nn.BatchNorm2d(out_channels * 4),
            )

        layers.append(
            Block(self.in_channels, out_channels, identity_downsample, stride)
        )

        self.in_channels = out_channels * 4
        for i in range(num_blocks - 1):
            layers.append(Block(self.in_channels, out_channels))

        return nn.Sequential(*layers)



I tried this.