text: #coding:utf-8
  import torch
  from torch import nn
  import torchvision as tv
  
  dropout = torch.nn.Dropout(p=0.8)
  relu = torch.nn.LeakyReLU()
  pool = nn.MaxPool2d(2, 2)
  
  class ConvRes(nn.Module):
      def __init__(self, insize, outsize):
          super(ConvRes, self).__init__()
          drate = .3
          self.math = nn.Sequential(
              nn.BatchNorm2d(insize),
              # nn.Dropout(drate),
              torch.nn.Conv2d(insize, outsize, kernel_size=2, padding=2),
              nn.PReLU(),
          )
  
      def forward(self, x):
          return self.math(x)
  
  
  class ConvCNN(nn.Module):
      def __init__(self, insize, outsize, kernel_size=7, padding=2, pool=2, avg=True):
          super(ConvCNN, self).__init__()
          self.avg = avg
          self.math = torch.nn.Sequential(
              torch.nn.Conv2d(insize, outsize, kernel_size=kernel_size, padding=padding),
              torch.nn.BatchNorm2d(outsize),
              torch.nn.LeakyReLU(),
              torch.nn.MaxPool2d(pool, pool),
          )
          self.avgpool = torch.nn.AvgPool2d(pool, pool)
  
      def forward(self, x):
          x = self.math(x)
          if self.avg is True:
              x = self.avgpool(x)
          return x
  
  
  class SimpleNet(nn.Module):
      def __init__(self):
          super(SimpleNet, self).__init__()
  
          self.avgpool = nn.AdaptiveAvgPool2d(1)
  
          self.cnn1 = ConvCNN(2, 32, kernel_size=7, pool=4, avg=False)
          self.cnn2 = ConvCNN(32, 32, kernel_size=5, pool=2, avg=True)
          self.cnn3 = ConvCNN(32, 32, kernel_size=5, pool=2, avg=True)
  
          self.res1 = ConvRes(32, 64)
  
          self.features = nn.Sequential(
              self.cnn1, dropout,
              self.cnn2,
              self.cnn3,
              self.res1,
          )
  
          self.classifier = torch.nn.Sequential(
              nn.Linear(1024, 1),
          )
          self.sig = nn.Sigmoid()
  
      def forward(self, x):
          x = self.features(x)
          x = x.view(x.size(0), -1)
          x = self.classifier(x)
          x = self.sig(x)
          return x
  
  
  class ResNetLike(nn.Module):
      def __init__(self, block, layers, num_channels=2, num_classes=1):
          self.inplanes = 32
          super(ResNetLike, self).__init__()
          self.conv1 = nn.Conv2d(num_channels, 32, kernel_size=7, stride=2, padding=3,
                                 bias=False)
          self.bn1 = nn.BatchNorm2d(32)
          self.relu = nn.ReLU(inplace=True)
          self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
          self.layer1 = self._make_layer(block, 32, layers[0])
          self.dropout1 = nn.Dropout2d(p=0.3)
          self.layer2 = self._make_layer(block, 64, layers[1], stride=2)
          # self.dropout2 = nn.Dropout2d(p=0.3)
          # self.layer3 = self._make_layer(block, 128, layers[2], stride=2)
          # self.dropout3 = nn.Dropout2d(p=0.3)
          # self.layer4 = self._make_layer(block, 128, layers[3], stride=2)
          self.avgpool = nn.AvgPool2d(7)
          self.fc = nn.Linear(64 , num_classes)
          self.sig = nn.Sigmoid()
  
          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))
              elif isinstance(m, nn.BatchNorm2d):
                  m.weight.data.fill_(1)
                  m.bias.data.zero_()
  
      def _make_layer(self, block, planes, blocks, stride=1):
          downsample = None
          if stride != 1 or self.inplanes != planes * block.expansion:
              downsample = nn.Sequential(
                  nn.Conv2d(self.inplanes, planes * block.expansion,
                            kernel_size=1, stride=stride, bias=False),
                  nn.BatchNorm2d(planes * block.expansion),
              )
  
          layers = []
          layers.append(block(self.inplanes, planes, stride, downsample))
          self.inplanes = planes * block.expansion
          for i in range(1, blocks):
              layers.append(block(self.inplanes, planes))
  
          return nn.Sequential(*layers)
  
      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.dropout1(x)
          x = self.layer2(x)
          # x = self.dropout2(x)
          # x = self.layer3(x)
          # x = self.dropout3(x)
          # x = self.layer4(x)
  
          x = self.avgpool(x)
          x = x.view(x.size(0), -1)
          # print (x.data.shape)
          x = self.fc(x)
          x = self.sig(x)
          return x
  