text: import torch
  import torch.nn as nn
  from torchvision import models
  
  
  def double_conv(in_channels, out_channels):
      return nn.Sequential(
          nn.Conv2d(in_channels, out_channels, 3, padding=1),
          nn.ReLU(inplace=True),
          nn.Conv2d(out_channels, out_channels, 3, padding=1),
          nn.ReLU(inplace=True)
      )
  
  
  class BasicBlock(nn.Module):
      expansion = 1
  
      def __init__(self, in_channels, out_channels, stride=1):
          super().__init__()
          # residual function
          self.residual_function = nn.Sequential(
              nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, padding=1, bias=False),
              nn.BatchNorm2d(out_channels),
              nn.ReLU(inplace=True),
              nn.Conv2d(out_channels, out_channels * BasicBlock.expansion, kernel_size=3, padding=1, bias=False),
              nn.BatchNorm2d(out_channels * BasicBlock.expansion)
          )
          # shortcut
          self.shortcut = nn.Sequential()
          if stride != 1 or in_channels != BasicBlock.expansion * out_channels:
              self.shortcut = nn.Sequential(
                  nn.Conv2d(in_channels, out_channels * BasicBlock.expansion, kernel_size=1, stride=stride, bias=False),
                  nn.BatchNorm2d(out_channels * BasicBlock.expansion)
              )
  
      def forward(self, x):
          return nn.ReLU(inplace=True)(self.residual_function(x) + self.shortcut(x))
  
  
  class ResNet(nn.Module):
      def __init__(self, in_channel, out_channel, block, num_block):
          super().__init__()
          self.in_channels = 64
          self.conv1 = nn.Sequential(
              nn.Conv2d(in_channel, 64, kernel_size=7, stride=2, padding=3, bias=False),
              nn.BatchNorm2d(64),
              nn.ReLU(inplace=True))
          self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
          self.conv2_x = self.ayer(block, 64, num_block[0], 2)
          self.conv3_x = self.layer(block, 128, num_block[1], 2)
          self.conv4_x = self.layer(block, 256, num_block[2], 2)
          self.conv5_x = self.layer(block, 512, num_block[3], 2)
          self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
  
          self.dconv_up3 = double_conv(256 + 512, 256)
          self.dconv_up2 = double_conv(128 + 256, 128)
          self.dconv_up1 = double_conv(128 + 64, 64)
  
          self.dconv_last = nn.Sequential(
              nn.Conv2d(128, 64, 3, padding=1),
              nn.BatchNorm2d(64),
              nn.ReLU(inplace=True),
              nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True),
              nn.Conv2d(64, out_channel, 1)
          )
  
      def make_layer(self, block, out_channels, num_blocks, stride):
          strides = [stride] + [1] * (num_blocks - 1)
          layers = []
          for stride in strides:
              layers.append(block(self.in_channels, out_channels, stride))
              self.in_channels = out_channels * block.expansion
          return nn.Sequential(*layers)
  
      def forward(self, x):
          conv1 = self.conv1(x)
          temp = self.maxpool(conv1)
          conv2 = self.conv2_x(temp)
          conv3 = self.conv3_x(conv2)
          conv4 = self.conv4_x(conv3)
          bottle = self.conv5_x(conv4)
          x = self.upsample(bottle)
          x = torch.cat([x, conv4], dim=1)
  
          x = self.dconv_up3(x)
          x = self.upsample(x)
          x = torch.cat([x, conv3], dim=1)
  
          x = self.dconv_up2(x)
          x = self.upsample(x)
          x = torch.cat([x, conv2], dim=1)
  
          x = self.dconv_up1(x)
          x = self.upsample(x)
          # print(x.shape)
          # print(conv1.shape)
          x = torch.cat([x, conv1], dim=1)
          out = self.dconv_last(x)
  
  
  def resnet34(in_channel, out_channel):
      model = ResNet(in_channel, out_channel, BasicBlock, [3, 4, 6, 3])
      return model
  