text: #coding:utf-8
  from mxnet.gluon import nn
  from mxnet import nd
  from mxnet import init
  
  class Residual(nn.HybridBlock):
      def __init__(self, channels, same_shape=True, **kwargs):
          super(Residual, self).__init__(**kwargs)
          self.same_shape = same_shape
          with self.name_scope():
              strides = 1 if same_shape else 2
              self.conv1 = nn.Conv2D(channels, kernel_size=3, padding=1,
                                    strides=strides)
              self.bn1 = nn.BatchNorm()
              self.conv2 = nn.Conv2D(channels, kernel_size=3, padding=1)
              self.bn2 = nn.BatchNorm()
              if not same_shape:
                  self.conv3 = nn.Conv2D(channels, kernel_size=1,
                                        strides=strides)
  
      def hybrid_forward(self, F, x):
          out = F.relu(self.bn1(self.conv1(x)))
          out = self.bn2(self.conv2(out))
          if not self.same_shape:
              x = self.conv3(x)
          return F.relu(out + x)
  
  
  class ResNet(nn.HybridBlock):
      def __init__(self, num_classes, verbose=False, **kwargs):
          super(ResNet, self).__init__(**kwargs)
          self.verbose = verbose
          with self.name_scope():
              net = self.net = nn.HybridSequential()
              # 模块1
              net.add(nn.Conv2D(channels=32, kernel_size=3, strides=1,
                                padding=1))
              net.add(nn.BatchNorm())
              net.add(nn.Activation(activation='relu'))
              # 模块2
              for _ in range(3):
                  net.add(Residual(channels=32))
              # 模块3
              net.add(Residual(channels=64, same_shape=False))
              for _ in range(2):
                  net.add(Residual(channels=64))
              # 模块4
              net.add(Residual(channels=128, same_shape=False))
              for _ in range(2):
                  net.add(Residual(channels=128))
              # 模块5
              net.add(nn.GlobalAvgPool2D())
              net.add(nn.Flatten())
              net.add(nn.Dense(num_classes))
  
      def hybrid_forward(self, F, x):
          out = x
          for i, b in enumerate(self.net):
              out = b(out)
              if self.verbose:
                  print('Block %d output: %s'%(i+1, out.shape))
          return out
  
  
  def get_net(ctx):
      num_outputs = 120
      net = ResNet(num_outputs)
      net.initialize(ctx=ctx, init=init.Xavier())
      return net