text: import torch.nn as nn
  import torch
  from torchsummary import summary
  from torch.hub import load_state_dict_from_url
  
  # modified based on https://github.com/thuml/CDAN/blob/master/pytorch/alexnet.py
  
  
  __all__ = ['AlexNet', 'alexnet']
  
  # 
  model_urls = {
      # Note that the alexnet structure used here is different from the pytorch original implementation of alexnet,
      # if you want to use the pretrained model from pytorch, you might get the underperformed results
      'alexnet': 'https://download.pytorch.org/models/alexnet-owt-7be5be79.pth',
  }
  
  class LRN(nn.Module):
      def __init__(self, local_size=1, alpha=1.0, beta=0.75, ACROSS_CHANNELS=True):
          super(LRN, self).__init__()
          self.ACROSS_CHANNELS = ACROSS_CHANNELS
          if ACROSS_CHANNELS:
              self.average=nn.AvgPool3d(kernel_size=(local_size, 1, 1),
                      stride=1,
                      padding=(int((local_size-1.0)/2), 0, 0))
          else:
              self.average=nn.AvgPool2d(kernel_size=local_size,
                      stride=1,
                      padding=int((local_size-1.0)/2))
          self.alpha = alpha
          self.beta = beta
  
  
      def forward(self, x):
          if self.ACROSS_CHANNELS:
              div = x.pow(2).unsqueeze(1)
              div = self.average(div).squeeze(1)
              div = div.mul(self.alpha).add(1.0).pow(self.beta)
          else:
              div = x.pow(2)  
              div = self.average(div)
              div = div.mul(self.alpha).add(1.0).pow(self.beta)
          x = x.div(div)
          return x
  class AlexNet(nn.Module):
  
      def __init__(self, num_classes=1000):
          self.num_classes = num_classes
          super(AlexNet, self).__init__()
          self.features = nn.Sequential(
              nn.Conv2d(3, 96, kernel_size=11, stride=4, padding=0),
              nn.ReLU(inplace=True),
              LRN(local_size=5, alpha=0.0001, beta=0.75),
              nn.MaxPool2d(kernel_size=3, stride=2),
              nn.Conv2d(96, 256, kernel_size=5, padding=2, groups=2),
              nn.ReLU(inplace=True),
              LRN(local_size=5, alpha=0.0001, beta=0.75),
              nn.MaxPool2d(kernel_size=3, stride=2),
              nn.Conv2d(256, 384, kernel_size=3, padding=1),
              nn.ReLU(inplace=True),
              nn.Conv2d(384, 384, kernel_size=3, padding=1, groups=2),
              nn.ReLU(inplace=True),
              nn.Conv2d(384, 256, kernel_size=3, padding=1, groups=2),
              nn.ReLU(inplace=True),
              nn.MaxPool2d(kernel_size=3, stride=2),
          )
          self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
          self.classifier = nn.Sequential(
              nn.Linear(256 * 6 * 6, 4096),
              nn.ReLU(inplace=True),
              nn.Dropout(),
              nn.Linear(4096, 4096),
              nn.ReLU(inplace=True),
              nn.Dropout(),
              nn.Linear(4096, self.num_classes),
          )
          self._out_features = 256
  
      def forward(self, x):
          x = self.features(x)
          x = self.avgpool(x)
          x = torch.flatten(x, 1)
          x = x.view(-1, self._out_features)
          # Masked the the rest of fully connected layers for fine tuning
          # x = x.view(x.size(0), 256 * 6 * 6)
          # x = self.classifier(x)
  
          return x
  
      
      @property
      def out_features(self) -> int:
          """The dimension of output features"""
          return self._out_features
  
      # def copy_head(self) -> nn.Module:
      #     """Copy the origin fully connected layer"""
      #     return copy.deepcopy(self.fc)        
  
  
  
  def alexnet_cdan(pretrained=False, **kwargs):
      r"""AlexNet model architecture from the
      `"One weird trick..." <https://arxiv.org/abs/1404.5997>`_ paper.
      Args:
          pretrained (bool): If True, returns a model pre-trained on ImageNet
      """
      model = AlexNet(**kwargs)
      print("the number of classes are in the alexnet cdan %d" % (model.num_classes))
      print(summary(model.cuda(), (3,256,256)))
      # if pretrained:
      #     model_path = './alexnet.pth.tar'
      #     pretrained_model = torch.load(model_path)
      #     model.load_state_dict(pretrained_model['state_dict'])
  
      return model