示例#1
0
    def _fire_layer(
            self,
            name: str,
            inputs: sym.Variable,
            s1x1: int,
            e1x1: int,
            e3x3: int):
        """Fire layer constructor. Written by Bichen Wu from UC Berkeley.

        Args:
          layer_name: layer name
          inputs: input tensor
          s1x1: number of 1x1 filters in squeeze layer.
          e1x1: number of 1x1 filters in expand layer.
          e3x3: number of 3x3 filters in expand layer.
          freeze: if true, do not train parameters in this layer.
        Returns:
          fire layer operation.
        """
        sq1x1 = sym.Convolution(
            inputs, name=name+'/s1x1', num_filter=s1x1, kernel=(1, 1), stride=(1, 1))
        relu1 = sym.Activation(sq1x1, act_type='relu')
        ex1x1 = sym.Convolution(
            relu1, name=name+'/e1x1', num_filter=e1x1, kernel=(1, 1), stride=(1, 1))
        relu2 = sym.Activation(ex1x1, act_type='relu')
        ex3x3 = sym.Convolution(
            relu1, name=name+'/e3x3', num_filter=e3x3, kernel=(3, 3), stride=(1, 1), pad=(1, 1))
        relu3 = sym.Activation(ex3x3, act_type='relu')
        return sym.Concat(relu2, relu3, dim=1, name=name+'/concat')
示例#2
0
def tmpnet():
    x = sym.Variable('data')
    y = sym.Convolution(x, kernel=(3, 3), num_filter=32)
    y = sym.Activation(y, 'relu')
    y = sym.Convolution(y,
                        kernel=(3, 3),
                        num_filter=64,
                        stride=(2, 2),
                        num_group=2)
    y = sym.softmax(y)
    return y
示例#3
0
    def __call__(self, inputs, states):
        self._counter += 1
        name = '%st%d_' % (self._prefix, self._counter)

        #input
        i2h = symbol.Convolution(data=inputs, weight=self._iW, bias=self._iB,kernel=self._kernel,
                                    num_filter=self._num_hidden,stride=self._stride,name='%si2h' % name)

        #memory
        h2h = symbol.Convolution(data=states[0], weight=self._hW, bias=self._hB,
                                 kernel=self._kernel,num_filter=self._num_hidden,stride=self._stride,name='%sh2h' % name)

        output = self._get_activation(i2h+h2h, self._activation,
                                      name='%sout' % name)

        return output, [output]
示例#4
0
def getsymbol(num_classes=136):
    # define alexnet
    data = mxy.Variable(name="data")
    label = mxy.Variable(name="label")

    # group 1
    conv1_1 = mxy.Convolution(data=data, kernel=(3, 3), pad=(1, 1), num_filter=64, name="conv1_1")
    relu1_1 = mxy.Activation(data=conv1_1, act_type="relu", name="relu1_1")
    pool1 = mxy.Pooling(data=relu1_1, pool_type="max", kernel=(2, 2), stride=(2,2), name="pool1")

    # group 2
    conv2_1 = mxy.Convolution(data=pool1, kernel=(3, 3), pad=(1, 1), num_filter=128, name="conv2_1")
    relu2_1 = mxy.Activation(data=conv2_1, act_type="relu", name="relu2_1")
    pool2 = mxy.Pooling(data=relu2_1, pool_type="max", kernel=(2, 2), stride=(2,2), name="pool2")

    # group 3
    conv3_1 = mxy.Convolution(data=pool2, kernel=(3, 3), pad=(1, 1), num_filter=256, name="conv3_1")
    relu3_1 = mxy.Activation(data=conv3_1, act_type="relu", name="relu3_1")
    conv3_2 = mxy.Convolution(data=relu3_1, kernel=(3, 3), pad=(1, 1), num_filter=256, name="conv3_2")
    relu3_2 = mxy.Activation(data=conv3_2, act_type="relu", name="relu3_2")
    pool3 = mxy.Pooling(data=relu3_2, pool_type="max", kernel=(2, 2), stride=(2,2), name="pool3")

    # group 4
    conv4_1 = mxy.Convolution(data=pool3, kernel=(3, 3), pad=(1, 1), num_filter=512, name="conv4_1")
    relu4_1 = mxy.Activation(data=conv4_1, act_type="relu", name="relu4_1")
    conv4_2 = mxy.Convolution(data=relu4_1, kernel=(3, 3), pad=(1, 1), num_filter=512, name="conv4_2")
    relu4_2 = mxy.Activation(data=conv4_2, act_type="relu", name="relu4_2")
    pool4 = mxy.Pooling(data=relu4_2, pool_type="max", kernel=(2, 2), stride=(2,2), name="pool4")

    # group 5
    conv5_1 = mxy.Convolution(data=pool4, kernel=(3, 3), pad=(1, 1), num_filter=512, name="conv5_1")
    relu5_1 = mxy.Activation(data=conv5_1, act_type="relu", name="relu5_1")
    conv5_2 = mxy.Convolution(data=relu5_1, kernel=(3, 3), pad=(1, 1), num_filter=512, name="conv5_2")
    relu5_2 = mxy.Activation(data=conv5_2, act_type="relu", name="conv1_2")
    pool5 = mxy.Pooling(data=relu5_2, pool_type="max", kernel=(2, 2), stride=(2,2), name="pool5")

    # group 6
    flatten = mxy.Flatten(data=pool5, name="flatten")
    fc6 = mxy.FullyConnected(data=flatten, num_hidden=4096, name="fc6")
    relu6 = mxy.Activation(data=fc6, act_type="relu", name="relu6")
    drop6 = mxy.Dropout(data=relu6, p=0.5, name="drop6")

    # group 7
    fc7 = mxy.FullyConnected(data=drop6, num_hidden=4096, name="fc7")
    relu7 = mxy.Activation(data=fc7, act_type="relu", name="relu7")
    drop7 = mxy.Dropout(data=relu7, p=0.5, name="drop7")

    # output
    fc8 = mxy.FullyConnected(data=drop7, num_hidden=num_classes, name="fc8")
    loc_loss = mxy.LinearRegressionOutput(data=fc8, label=label, name="loc_loss")

    #loc_loss_ = mxy.smooth_l1(name="loc_loss_", data=(fc8 - label), scalar=1.0)
    #loc_loss_ = mxy.smooth_l1(name="loc_loss_", data=fc8, scalar=1.0)
    #loc_loss = mx.sym.MakeLoss(name='loc_loss', data=loc_loss_)

    return loc_loss
def weight_sharing_residual_network(graph):
  X = symbol.Variable('data')
  for index, node in enumerate(graph):
    weight = symbol.Variable('convolution_weight_%d' % index)
    bias = symbol.Variable('convolution_bias_%d' % index)
    kwargs, activation, times = node
    for t in range(times):
      X = symbol.Convolution(data = X, weight = weight, bias = bias, **kwargs)
示例#6
0
def get_conv(inpt, name, num_filter, stride=(1, 1), act_type='prelu'):
    act_name = name.replace('conv', act_type)
    return sym.LeakyReLU(sym.Convolution(inpt,
                                         name=name,
                                         num_filter=num_filter,
                                         stride=stride,
                                         kernel=(3, 3),
                                         pad=(1, 1)),
                         name=act_name,
                         act_type=act_type,
                         gamma=sym.var(act_name))
示例#7
0
    def __call__(self, inputs, states):
        # pylint: disable=too-many-locals
        self._counter += 1

        seq_idx = self._counter
        name = '%st%d_' % (self._prefix, seq_idx)
        prev_state_h = states[0]

        i2h = symbol.Convolution(data=inputs,
                                 weight=self._iW,
                                 kernel  = self._kernel,
                                 bias=self._iB,
                                 num_filter=self._num_hidden * 3,
                                 dilate =self._dilate,
                                 pad = self._pad,
                                 name="%s_i2h" % name)

        h2h = symbol.Convolution(data=prev_state_h,
                                 kernel=self._kernel,
                                 weight=self._hW,
                                 bias=self._hB,
                                 num_filter=self._num_hidden * 3,
                                 dilate=self._dilate,
                                 pad = self._pad,
                                 name="%s_h2h" % name)

        i2h_r, i2h_z, i2h = symbol.SliceChannel(i2h, num_outputs=3, name="%s_i2h_slice" % name)
        h2h_r, h2h_z, h2h = symbol.SliceChannel(h2h, num_outputs=3, name="%s_h2h_slice" % name)

        reset_gate = symbol.Activation(i2h_r + h2h_r, act_type="sigmoid",
                                       name="%s_r_act" % name)
        update_gate = symbol.Activation(i2h_z + h2h_z, act_type="sigmoid",
                                        name="%s_z_act" % name)

        next_h_tmp = symbol.Activation(i2h + reset_gate * h2h, act_type="tanh",
                                       name="%s_h_act" % name)

        next_h = symbol._internal._plus((1. - update_gate) * next_h_tmp, update_gate * prev_state_h,
                                        name='%sout' % name)

        return next_h, [next_h]
示例#8
0
 def add_forward(self, data: sym.Variable):
     """Add neural network model."""
     conv1 = sym.Convolution(
         data, name='conv1', num_filter=64, kernel=(3, 3), stride=(2, 2))
     relu1 = sym.Activation(conv1, act_type='relu')
     pool1 = sym.Pooling(relu1, pool_type='max', kernel=(3, 3), stride=(2, 2))
     fire2 = self._fire_layer('fire2', pool1, s1x1=16, e1x1=64, e3x3=64)
     fire3 = self._fire_layer('fire3', fire2, s1x1=16, e1x1=64, e3x3=64)
     pool3 = sym.Pooling(fire3, name='pool3', kernel=(3, 3), stride=(2, 2), pool_type='max')
     fire4 = self._fire_layer('fire4', pool3, s1x1=32, e1x1=128, e3x3=128)
     fire5 = self._fire_layer('fire5', fire4, s1x1=32, e1x1=128, e3x3=128)
     pool5 = sym.Pooling(fire5, name='pool5', kernel=(3, 3), stride=(2, 2), pool_type='max')
     fire6 = self._fire_layer('fire6', pool5, s1x1=48, e1x1=192, e3x3=192)
     fire7 = self._fire_layer('fire7', fire6, s1x1=48, e1x1=192, e3x3=192)
     fire8 = self._fire_layer('fire8', fire7, s1x1=64, e1x1=256, e3x3=256)
     fire9 = self._fire_layer('fire9', fire8, s1x1=64, e1x1=256, e3x3=256)
     fire10 = self._fire_layer('fire10', fire9, s1x1=96, e1x1=384, e3x3=384)
     fire11 = self._fire_layer('fire11', fire10, s1x1=96, e1x1=384, e3x3=384)
     dropout11 = sym.Dropout(fire11, p=0.1, name='drop11')
     return sym.Convolution(
         dropout11, name='conv12', num_filter=NUM_OUT_CHANNELS,
         kernel=(3, 3), stride=(1, 1), pad=(1, 1))
示例#9
0
def SEModule(data, num_filter, name):
    body = sym.Pooling(data=data,
                       global_pool=True,
                       kernel=(7, 7),
                       pool_type='avg',
                       name=name + '_se_pool1')
    body = sym.Convolution(data=body,
                           num_filter=num_filter // 8,
                           kernel=(1, 1),
                           stride=(1, 1),
                           pad=(0, 0),
                           name=name + "_se_conv1")
    body = Act(data=body, act_type="prelu", name=name + '_se_relu1')
    body = sym.Convolution(data=body,
                           num_filter=num_filter,
                           kernel=(1, 1),
                           stride=(1, 1),
                           pad=(0, 0),
                           name=name + "_se_conv2")
    body = sym.Activation(data=body,
                          act_type='sigmoid',
                          name=name + "_se_sigmoid")
    data = sym.broadcast_mul(data, body)
    return data
def C(idx, indata, bn):
    n = idx
    p = Param['c%d' % idx]

    conv = S.Convolution(name='c' + n,
                         data=indata,
                         kernel=p['fsize'],
                         num_filter=p['fnum'],
                         pad=p['pad'],
                         stride=p['stride'],
                         weight=P[i * 2],
                         bias=P[i * 2 + 1])
    if bn:
        c = mx.sym.BatchNorm(name='b' + n, data=c)
    r = mx.sym.Activation(name='r' + n, data=c, act_type='relu')
    return r
示例#11
0
def ConvOnly(data,
             num_filter=1,
             kernel=(1, 1),
             stride=(1, 1),
             pad=(0, 0),
             num_group=1,
             name=None,
             suffix=''):
    conv = sym.Convolution(data=data,
                           num_filter=num_filter,
                           kernel=kernel,
                           num_group=num_group,
                           stride=stride,
                           pad=pad,
                           no_bias=True,
                           name='%s%s_conv2d' % (name, suffix))
    return conv
示例#12
0
def Linear(data,
           num_filter=1,
           kernel=(1, 1),
           stride=(1, 1),
           pad=(0, 0),
           num_group=1,
           name=None,
           suffix=''):
    conv = sym.Convolution(data=data,
                           num_filter=num_filter,
                           kernel=kernel,
                           num_group=num_group,
                           stride=stride,
                           pad=pad,
                           no_bias=True,
                           name='%s%s_conv2d' % (name, suffix))
    bn = sym.BatchNorm(data=conv,
                       name='%s%s_batchnorm' % (name, suffix),
                       fix_gamma=False,
                       momentum=config.bn_mom)
    return bn
示例#13
0
    def C(idx, indata, bn):
        p = Param['c%d' % idx]
        i = 4 * (idx - 1)

        c = S.Convolution(name='c' + str(idx),
                          data=indata,
                          kernel=p['fsize'],
                          num_filter=p['fnum'],
                          pad=p['pad'],
                          stride=p['stride'],
                          weight=P[i],
                          bias=P[i + 1])
        if bn:
            c = mx.sym.BatchNorm(
                name='b' + str(next(gtr)),
                data=c,
                gamma=P[i + 2],
                beta=P[i + 3],
            )
        r = mx.sym.Activation(name='r' + str(idx), data=c, act_type='relu')
        return r
示例#14
0
def ConvFactory(data,
                num_filter,
                kernel,
                stride=(1, 1),
                pad=(0, 0),
                name=None,
                suffix='',
                attr={}):
    conv = mxy.Convolution(data=data,
                           num_filter=num_filter,
                           kernel=kernel,
                           stride=stride,
                           pad=pad,
                           name='conv_%s%s' % (name, suffix))
    bn = mxy.BatchNorm(data=conv,
                       fix_gamma=fix_gamma,
                       eps=eps,
                       momentum=bn_mom,
                       name='bn_%s%s' % (name, suffix))
    act = mxy.Activation(data=bn,
                         act_type='relu',
                         name='relu_%s%s' % (name, suffix),
                         attr=attr)
    return act
示例#15
0
def r_lstm_step(X, num_hidden, C, c=None, h=None, idx='', param=None):

    if not isinstance(idx, str):
        idx = str(idx)
    if not c:
        c = mx.sym.Variable(name='c%s' % idx)
    if not h:
        h = mx.sym.Variable(name='h%s' % idx)
    if not param:
        param = LSTMParam(x2g_weight=S.Variable("x2g_weight"),
                          x2g_bias=S.Variable("x2g_bias"),
                          h2g_weight=S.Variable("h2g_weight"),
                          h2g_bias=S.Variable("h2g_bias"),
                          Y_weight=S.Variable("Y_weight"),
                          Y_bias=S.Variable("Y_bias"))

    x2g = S.Convolution(name='x2g%s' % idx,
                        data=X,
                        weight=param.x2g_weight,
                        bias=param.x2g_bias,
                        kernel=(5, 5),
                        num_filter=num_hidden * 4,
                        pad=(2, 2))
    h2g = S.Convolution(name='h2g%s' % idx,
                        data=h,
                        weight=param.h2g_weight,
                        bias=param.h2g_bias,
                        kernel=(5, 5),
                        num_filter=num_hidden * 4,
                        pad=(2, 2))

    gates = x2g + h2g
    slice_gates = mx.sym.SliceChannel(gates,
                                      num_outputs=4,
                                      name='rnn_slice%s' % idx)
    in_gate = mx.sym.Activation(slice_gates[0],
                                act_type="sigmoid",
                                name='in_gate%s' % idx)
    in_transform = mx.sym.Activation(slice_gates[1],
                                     act_type="tanh",
                                     name='in_transform%s' % idx)
    forget_gate = mx.sym.Activation(slice_gates[2],
                                    act_type="sigmoid",
                                    name='forget_gate%s' % idx)
    out_gate = mx.sym.Activation(slice_gates[3],
                                 act_type="sigmoid",
                                 name='out_gate%s' % idx)

    c_this = (forget_gate * c) + (in_gate * in_transform)
    h_this = out_gate * mx.sym.Activation(
        c_this, act_type="tanh", name='tanh2h%s' % idx)

    fc = S.Convolution(name='Y%s' % idx,
                       data=h_this,
                       weight=param.Y_weight,
                       bias=param.Y_bias,
                       kernel=(1, 1),
                       num_filter=C,
                       pad=(0, 0))
    c_this = mx.sym.BlockGrad(data=c_this)
    h_this = mx.sym.BlockGrad(data=h_this)

    return fc, c_this, h_this
示例#16
0
# try overlap in future
p1 = maxpool(l1_3)              #128,128

l2_1 = conv_relu('4', data=p1,   kernel=(3,3), num_filter=64, pad=(1,1))
l2_2 = conv_relu('5', data=l2_1, kernel=(3,3), num_filter=64, pad=(1,1))
l2_3 = conv_relu('6', data=l2_2, kernel=(3,3), num_filter=64, pad=(1,1), bn=True)

p2 = maxpool(l2_3)
p1_5  = maxpool(p1)
p2 = p2+p1_5                       #64,64

l3_1 = conv_relu('7', data=p2,   kernel=(3,3), num_filter=64, pad=(1,1))
l3_2 = conv_relu('8', data=l3_1, kernel=(3,3), num_filter=16, pad=(1,1))
l3_3 = conv_relu('9', data=l3_2, kernel=(3,3), num_filter=16, pad=(1,1), bn=True)
l3_4 = S.Convolution(name='c10', data=l3_3, kernel=(1,1), num_filter=1, pad=(0,0))

pred = S.LogisticRegressionOutput(data=l3_4, name='softmax')


def e_net(*args):
    return pred


def e_rnn(*args):
    return LSTM(l3_4, 64*64, 1, 64, 64)

if __name__ == '__main__':
    for _ in pred.infer_shape(data=(11,1,256,256)):
        print _
示例#17
0
 def conv_bn_relu_pool_siamese(input_a,
                               input_b,
                               kernel,
                               num_filter,
                               pad,
                               stride,
                               name_postfix,
                               use_pooling=False,
                               p_kernel=None,
                               p_stride=None,
                               use_batch_norm=True):
     conv_weight = mxs.Variable(name='conv' + name_postfix + '_weight')
     conv_bias = mxs.Variable(name='conv' + name_postfix + '_bias')
     conv_a = mxs.Convolution(data=input_a,
                              kernel=kernel,
                              num_filter=num_filter,
                              pad=pad,
                              stride=stride,
                              name='conv' + name_postfix + "_a",
                              weight=conv_weight,
                              bias=conv_bias)
     conv_b = mxs.Convolution(data=input_b,
                              kernel=kernel,
                              num_filter=num_filter,
                              pad=pad,
                              stride=stride,
                              name='conv' + name_postfix + "_b",
                              weight=conv_weight,
                              bias=conv_bias)
     if use_batch_norm:
         bn_gamma = mxs.Variable(name='bn' + name_postfix + '_gamma')
         bn_beta = mxs.Variable(name='bn' + name_postfix + '_beta')
         bn_moving_mean = mxs.Variable(name='bn' + name_postfix +
                                       '_moving_mean')
         bn_moving_var = mxs.Variable(name='bn' + name_postfix +
                                      '_moving_var')
         batch_norm_a = mxs.BatchNorm(data=conv_a,
                                      name='bn' + name_postfix + '_a',
                                      gamma=bn_gamma,
                                      beta=bn_beta,
                                      moving_mean=bn_moving_mean,
                                      moving_var=bn_moving_var)
         batch_norm_b = mxs.BatchNorm(data=conv_b,
                                      name='bn' + name_postfix + '_b',
                                      gamma=bn_gamma,
                                      beta=bn_beta,
                                      moving_mean=bn_moving_mean,
                                      moving_var=bn_moving_var)
     else:
         batch_norm_a = conv_a
         batch_norm_b = conv_b
     relu_a = mxs.relu(data=batch_norm_a, name='relu' + name_postfix + '_a')
     relu_b = mxs.relu(data=batch_norm_b, name='relu' + name_postfix + '_b')
     if use_pooling:
         out_a = mxs.Pooling(data=relu_a,
                             kernel=p_kernel,
                             pool_type='max',
                             stride=p_stride,
                             name='pool' + name_postfix + '_a')
         out_b = mxs.Pooling(data=relu_b,
                             kernel=p_kernel,
                             pool_type='max',
                             stride=p_stride,
                             name='pool' + name_postfix + '_b')
     else:
         out_a = relu_a
         out_b = relu_b
     return out_a, out_b
示例#18
0
def siamese_simp_net():
    def conv_bn_relu_pool_siamese(input_a,
                                  input_b,
                                  kernel,
                                  num_filter,
                                  pad,
                                  stride,
                                  name_postfix,
                                  use_pooling=False,
                                  p_kernel=None,
                                  p_stride=None,
                                  use_batch_norm=True):
        conv_weight = mxs.Variable(name='conv' + name_postfix + '_weight')
        conv_bias = mxs.Variable(name='conv' + name_postfix + '_bias')
        conv_a = mxs.Convolution(data=input_a,
                                 kernel=kernel,
                                 num_filter=num_filter,
                                 pad=pad,
                                 stride=stride,
                                 name='conv' + name_postfix + "_a",
                                 weight=conv_weight,
                                 bias=conv_bias)
        conv_b = mxs.Convolution(data=input_b,
                                 kernel=kernel,
                                 num_filter=num_filter,
                                 pad=pad,
                                 stride=stride,
                                 name='conv' + name_postfix + "_b",
                                 weight=conv_weight,
                                 bias=conv_bias)
        if use_batch_norm:
            bn_gamma = mxs.Variable(name='bn' + name_postfix + '_gamma')
            bn_beta = mxs.Variable(name='bn' + name_postfix + '_beta')
            bn_moving_mean = mxs.Variable(name='bn' + name_postfix +
                                          '_moving_mean')
            bn_moving_var = mxs.Variable(name='bn' + name_postfix +
                                         '_moving_var')
            batch_norm_a = mxs.BatchNorm(data=conv_a,
                                         name='bn' + name_postfix + '_a',
                                         gamma=bn_gamma,
                                         beta=bn_beta,
                                         moving_mean=bn_moving_mean,
                                         moving_var=bn_moving_var)
            batch_norm_b = mxs.BatchNorm(data=conv_b,
                                         name='bn' + name_postfix + '_b',
                                         gamma=bn_gamma,
                                         beta=bn_beta,
                                         moving_mean=bn_moving_mean,
                                         moving_var=bn_moving_var)
        else:
            batch_norm_a = conv_a
            batch_norm_b = conv_b
        relu_a = mxs.relu(data=batch_norm_a, name='relu' + name_postfix + '_a')
        relu_b = mxs.relu(data=batch_norm_b, name='relu' + name_postfix + '_b')
        if use_pooling:
            out_a = mxs.Pooling(data=relu_a,
                                kernel=p_kernel,
                                pool_type='max',
                                stride=p_stride,
                                name='pool' + name_postfix + '_a')
            out_b = mxs.Pooling(data=relu_b,
                                kernel=p_kernel,
                                pool_type='max',
                                stride=p_stride,
                                name='pool' + name_postfix + '_b')
        else:
            out_a = relu_a
            out_b = relu_b
        return out_a, out_b

    data_a = mxs.Variable('data_a')
    data_b = mxs.Variable('data_b')
    c1_a, c1_b = conv_bn_relu_pool_siamese(data_a,
                                           data_b,
                                           kernel=(3, 3),
                                           num_filter=64,
                                           pad=(1, 1),
                                           stride=(1, 1),
                                           name_postfix='1',
                                           use_pooling=False)
    c1_0_a, c1_0_b = conv_bn_relu_pool_siamese(c1_a,
                                               c1_b,
                                               kernel=(3, 3),
                                               num_filter=32,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='1_0',
                                               use_pooling=False)
    c2_a, c2_b = conv_bn_relu_pool_siamese(c1_0_a,
                                           c1_0_b,
                                           kernel=(3, 3),
                                           num_filter=32,
                                           pad=(1, 1),
                                           stride=(1, 1),
                                           name_postfix='2',
                                           use_pooling=False)
    c2_1_a, c2_1_b = conv_bn_relu_pool_siamese(c2_a,
                                               c2_b,
                                               kernel=(3, 3),
                                               num_filter=32,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='2_1',
                                               use_pooling=True,
                                               p_kernel=(2, 2),
                                               p_stride=(2, 2))
    c2_2_a, c2_2_b = conv_bn_relu_pool_siamese(c2_1_a,
                                               c2_1_b,
                                               kernel=(3, 3),
                                               num_filter=32,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='2_2',
                                               use_pooling=False)
    c3_a, c3_b = conv_bn_relu_pool_siamese(c2_2_a,
                                           c2_2_b,
                                           kernel=(3, 3),
                                           num_filter=32,
                                           pad=(1, 1),
                                           stride=(1, 1),
                                           name_postfix='3',
                                           use_pooling=False)
    # conv4
    conv4_weight = mxs.Variable(name='conv4_weight')
    conv4_bias = mxs.Variable(name='conv4_bias')
    conv4_a = mxs.Convolution(data=c3_a,
                              kernel=(3, 3),
                              num_filter=64,
                              pad=(1, 1),
                              stride=(1, 1),
                              name='conv4_a',
                              weight=conv4_weight,
                              bias=conv4_bias)  # xavier
    conv4_b = mxs.Convolution(data=c3_b,
                              kernel=(3, 3),
                              num_filter=64,
                              pad=(1, 1),
                              stride=(1, 1),
                              name='conv4_b',
                              weight=conv4_weight,
                              bias=conv4_bias)  # xavier
    maxp4_a = mxs.Pooling(data=conv4_a,
                          kernel=(2, 2),
                          pool_type='max',
                          stride=(2, 2),
                          name='pool4_a')
    maxp4_b = mxs.Pooling(data=conv4_b,
                          kernel=(2, 2),
                          pool_type='max',
                          stride=(2, 2),
                          name='pool4_b')
    bn4_gamma = mxs.Variable(name='bn4_gamma')
    bn4_beta = mxs.Variable(name='bn4_beta')
    bn4_moving_mean = mxs.Variable(name='bn4_moving_mean')
    bn4_moving_var = mxs.Variable(name='bn4_moving_var')
    batch_norm_4_a = mxs.BatchNorm(data=maxp4_a,
                                   name='bn4_a',
                                   gamma=bn4_gamma,
                                   beta=bn4_beta,
                                   moving_mean=bn4_moving_mean,
                                   moving_var=bn4_moving_var)
    batch_norm_4_b = mxs.BatchNorm(data=maxp4_b,
                                   name='bn4_b',
                                   gamma=bn4_gamma,
                                   beta=bn4_beta,
                                   moving_mean=bn4_moving_mean,
                                   moving_var=bn4_moving_var)
    relu4_a = mxs.relu(data=batch_norm_4_a, name='relu4')
    relu4_b = mxs.relu(data=batch_norm_4_b, name='relu4')
    c4_1_a, c4_1_b = conv_bn_relu_pool_siamese(relu4_a,
                                               relu4_b,
                                               kernel=(3, 3),
                                               num_filter=64,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='4_1',
                                               use_pooling=False)
    c4_2_a, c4_2_b = conv_bn_relu_pool_siamese(c4_1_a,
                                               c4_1_b,
                                               kernel=(3, 3),
                                               num_filter=64,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='4_2',
                                               use_pooling=True,
                                               p_kernel=(2, 2),
                                               p_stride=(2, 2))
    c4_0_a, c4_0_b = conv_bn_relu_pool_siamese(c4_2_a,
                                               c4_2_b,
                                               kernel=(3, 3),
                                               num_filter=128,
                                               pad=(1, 1),
                                               stride=(1, 1),
                                               name_postfix='4_0',
                                               use_pooling=False)
    cccp4_a, cccp4_b = conv_bn_relu_pool_siamese(c4_0_a,
                                                 c4_0_b,
                                                 kernel=(1, 1),
                                                 num_filter=256,
                                                 pad=[],
                                                 stride=(1, 1),
                                                 name_postfix='_cccp4',
                                                 use_pooling=False,
                                                 use_batch_norm=False)
    cccp5_a, cccp5_b = conv_bn_relu_pool_siamese(cccp4_a,
                                                 cccp4_b,
                                                 kernel=(1, 1),
                                                 num_filter=64,
                                                 pad=[],
                                                 stride=(1, 1),
                                                 name_postfix='_cccp5',
                                                 use_pooling=True,
                                                 p_kernel=(2, 2),
                                                 p_stride=(2, 2),
                                                 use_batch_norm=False)
    cccp6_a, cccp6_b = conv_bn_relu_pool_siamese(cccp5_a,
                                                 cccp5_b,
                                                 kernel=(3, 3),
                                                 num_filter=64,
                                                 pad=(2, 2),
                                                 stride=(1, 1),
                                                 name_postfix='_cccp6',
                                                 use_pooling=False,
                                                 use_batch_norm=False)
    flat_a = mxs.flatten(cccp6_a)
    flat_b = mxs.flatten(cccp6_b)
    return flat_a, flat_b