code: def sg_densenet_layer(x, opt):
      r
      assert opt.dim is not None, 'dim is mandatory.'
      assert opt.num is not None, 'num is mandatory.'
  
      # default stride
      opt += tf.sg_opt(stride=1, act='relu', trans=True)
  
      # format convolutional layer name
      def cname(index):
          return opt.name if opt.name is None else opt.name + '_%d' % index
  
      # dense layer
      with tf.sg_context(bias=False, reuse=opt.reuse):
          out = x
          for i in range(opt.num):
              # dense block
              out_new = (out
                         .sg_bypass(act=opt.act, bn=True, name=cname(3 * i + 1))
                         .sg_conv(dim=opt.dim // 4, size=1, act=opt.act, bn=True, name=cname(3 * i + 2))
                         .sg_conv(dim=opt.dim, size=3, name=cname(3 * i + 3)))
              out = tf.concat([out_new, out], 3)
  
          # transition layer
          if opt.trans:
              out = (out
                     .sg_bypass(act=opt.act, bn=True, name=cname(3 * i + 4))
                     .sg_conv(size=1, name=cname(3 * i + 5))
                     .sg_pool(avg=True))
  
      return out
docs: r"""Applies basic architecture of densenet layer.
  
      Note that the fc layers in the original architecture
        will be replaced with fully convolutional layers.
        For convenience, We still call them fc layers, though.
  
      Args:
        x: A `Tensor`.
        opt:
            dim: An integer. Dimension for this resnet layer
            num: Number of times to repeat
            act: String. 'relu' (default). the activation function name
            trans: Boolean. If True(default), transition layer will be applied.
            reuse: Boolean(Optional). If True, all variables will be loaded from previous network.
            name: String. (optional) Used as convolution layer prefix
  
      Returns:
        A `Tensor`.