text: 
  # the code base on https://github.com/tonylins/pytorch-mobilenet-v2
  '''
  
  将relu6改成relu，添加fc层，方便转成其他格式的模型
  
  '''
  import torch.nn as nn
  import math
  import torch
  
  def conv_bn(inp, oup, stride):
      return nn.Sequential(
          nn.Conv2d(inp, oup, 3, stride, 1, bias=False),
          nn.BatchNorm2d(oup),
          nn.ReLU(inplace=True)
      )
  
  
  def conv_1x1_bn(inp, oup):
      return nn.Sequential(
          nn.Conv2d(inp, oup, 1, 1, 0, bias=False),
          nn.BatchNorm2d(oup),
          nn.ReLU(inplace=True)
      )
  
  # reference form : https://github.com/moskomule/senet.pytorch  
  class SELayer(nn.Module):
      def __init__(self, channel, reduction=8):
          super(SELayer, self).__init__()
          self.avg_pool = nn.AdaptiveAvgPool2d(1)
          self.fc = nn.Sequential(
                  nn.Linear(channel, channel // reduction),
                  nn.ReLU(inplace=True),
                  nn.Linear(channel // reduction, channel),
                  nn.Sigmoid()
          )
  
      def forward(self, x):
          b, c, _, _ = x.size()
          y = self.avg_pool(x).view(b, c)
          y = self.fc(y).view(b, c, 1, 1)
          return x * y
       
  class InvertedResidual(nn.Module):
      def __init__(self, inp, oup, stride, expand_ratio, downsample=None):
          super(InvertedResidual, self).__init__()
          self.stride = stride
          assert stride in [1, 2]
          self.downsample = downsample
  
          hidden_dim = round(inp * expand_ratio)
          self.use_res_connect = self.stride == 1 and inp == oup
  
          if expand_ratio == 1:
              self.conv = nn.Sequential(
                  # dw
                  nn.Conv2d(hidden_dim, hidden_dim, 3, stride, 1, groups=hidden_dim, bias=False),
                  nn.BatchNorm2d(hidden_dim),
                  nn.ReLU(inplace=True),
                  # pw-linear
                  nn.Conv2d(hidden_dim, oup, 1, 1, 0, bias=False),
                  nn.BatchNorm2d(oup),
              )
          else:
              self.conv = nn.Sequential(
                  # pw
                  nn.Conv2d(inp, hidden_dim, 1, 1, 0, bias=False),
                  nn.BatchNorm2d(hidden_dim),
                  nn.ReLU(inplace=True),
                  # dw
                  nn.Conv2d(hidden_dim, hidden_dim, 3, stride, 1, groups=hidden_dim, bias=False),
                  nn.BatchNorm2d(hidden_dim),
                  nn.ReLU(inplace=True),
                  # pw-linear
                  nn.Conv2d(hidden_dim, oup, 1, 1, 0, bias=False),
                  nn.BatchNorm2d(oup),
              )
  
      def forward(self, x):
          if self.use_res_connect:
              return x + self.conv(x)
          else:
              if self.downsample is not None:
                  return self.downsample(x) + self.conv(x)
              else:
                  return self.conv(x)
  
  
  class FeatherNet(nn.Module):
      def __init__(self, n_class=2, input_size=224, se = False, avgdown=False, width_mult=1.):
          super(FeatherNet, self).__init__()
          block = InvertedResidual
          input_channel = 32
          last_channel = 1024
          self.se = se
          self.avgdown = avgdown
          interverted_residual_setting = [
              # t, c, n, s
              [1, 16, 1, 2],
              [6, 32, 2, 2], # 56x56
              [6, 48, 6, 2], # 14x14
              [6, 64, 3, 2], # 7x7
          ]
  
          # building first layer
          assert input_size % 32 == 0
          input_channel = int(input_channel * width_mult)
          self.last_channel = int(last_channel * width_mult) if width_mult > 1.0 else last_channel
          self.features = [conv_bn(3, input_channel, 2)]
          # building inverted residual blocks
          for t, c, n, s in interverted_residual_setting:
              output_channel = int(c * width_mult)
              for i in range(n):
                  downsample = None
                  if i == 0:
                      if self.avgdown:
                          downsample = nn.Sequential(nn.AvgPool2d(2, stride=2),
                          nn.BatchNorm2d(input_channel),
                          nn.Conv2d(input_channel, output_channel , kernel_size=1, bias=False)
                          )
                      self.features.append(block(input_channel, output_channel, s, expand_ratio=t, downsample = downsample))
                  else:
                      self.features.append(block(input_channel, output_channel, 1, expand_ratio=t, downsample = downsample))
                  input_channel = output_channel
              if self.se:
                  self.features.append(SELayer(input_channel))
  
          # make it nn.Sequential
          self.features = nn.Sequential(*self.features)
  #         building last several layers        
          self.final_DW = nn.Sequential(nn.Conv2d(input_channel, input_channel, kernel_size=3, stride=2, padding=1,
                                    groups=input_channel, bias=False),
                                       )
  #         # building classifier
          self.dropout = nn.Dropout(0.2)
          self.fc = nn.Linear(self.last_channel, n_class)
  
  
          self._initialize_weights()
  
      def forward(self, input):
          x = self.features(input)
          x = self.final_DW(x)
          
          x = x.view(x.size(0), -1)
          x = self.dropout(x)
          out = self.fc(x)
          return out
  
      def _initialize_weights(self):
          for m in self.modules():
              if isinstance(m, nn.Conv2d):
                  n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                  m.weight.data.normal_(0, math.sqrt(2. / n))
                  if m.bias is not None:
                      m.bias.data.zero_()
              elif isinstance(m, nn.BatchNorm2d):
                  m.weight.data.fill_(1)
                  m.bias.data.zero_()
              elif isinstance(m, nn.Linear):
                  n = m.weight.size(1)
                  m.weight.data.normal_(0, 0.01)
                  m.bias.data.zero_()
  
  def FeatherNetA_R():
      model = FeatherNet(se = True)
      return model
  
  def FeatherNetB():
      model = FeatherNet(se = False,avgdown=False)
      return model
  
  
  