def residual_block(num, quant_skip_pattern=None):

    def conv_bn_layer(input, ch_out, filter_size, stride, padding, act='relu', bias_attr=False):
        tmp = fluid.layers.conv2d(input=input, filter_size=filter_size, num_filters=ch_out, stride=stride, padding=padding, act=None, bias_attr=bias_attr)
        return fluid.layers.batch_norm(input=tmp, act=act)
    data = fluid.layers.data(name='image', shape=[1, 1, 32, 32], dtype='float32', append_batch_size=False)
    label = fluid.layers.data(name='label', shape=[1, 1], dtype='int64', append_batch_size=False)
    hidden = data
    for _ in six.moves.xrange(num):
        conv = conv_bn_layer(hidden, 16, 3, 1, 1, act=None, bias_attr=True)
        short = conv_bn_layer(hidden, 16, 1, 1, 0, act=None)
        hidden = fluid.layers.elementwise_add(x=conv, y=short, act='relu')
    matmul_weight = fluid.layers.create_parameter(shape=[1, 16, 32, 32], dtype='float32')
    hidden = fluid.layers.matmul(hidden, matmul_weight, True, True)
    if quant_skip_pattern:
        with fluid.name_scope(quant_skip_pattern):
            pool = fluid.layers.pool2d(input=hidden, pool_size=2, pool_type='avg', pool_stride=2)
    else:
        pool = fluid.layers.pool2d(input=hidden, pool_size=2, pool_type='avg', pool_stride=2)
    fc = fluid.layers.fc(input=pool, size=10)
    loss = fluid.layers.cross_entropy(input=fc, label=label)
    loss = fluid.layers.mean(loss)
    return loss
def residual_block(num, quant_skip_pattern=None):

    def conv_bn_layer(input, ch_out, filter_size, stride, padding, act='relu', bias_attr=False):
        tmp = fluid.layers.conv2d(input=input, filter_size=filter_size, num_filters=ch_out, stride=stride, padding=padding, act=None, bias_attr=bias_attr)
        return fluid.layers.batch_norm(input=tmp, act=act)
    data = fluid.layers.data(name='image', shape=[1, 1, 32, 32], dtype='float32', append_batch_size=False)
    label = fluid.layers.data(name='label', shape=[1, 1], dtype='int64', append_batch_size=False)
    hidden = data
    for _ in six.moves.xrange(num):
        conv = conv_bn_layer(hidden, 16, 3, 1, 1, act=None, bias_attr=True)
        short = conv_bn_layer(hidden, 16, 1, 1, 0, act=None)
        hidden = fluid.layers.elementwise_add(x=conv, y=short, act='relu')
    matmul_weight = fluid.layers.create_parameter(shape=[1, 16, 32, 32], dtype='float32')
    hidden = fluid.layers.matmul(hidden, matmul_weight, True, True)
    if quant_skip_pattern:
        with fluid.name_scope(quant_skip_pattern):
            pool = fluid.layers.pool2d(input=hidden, pool_size=2, pool_type='avg', pool_stride=2)
    else:
        pool = fluid.layers.pool2d(input=hidden, pool_size=2, pool_type='avg', pool_stride=2)
    fc = fluid.layers.fc(input=pool, size=10)
    loss = fluid.layers.cross_entropy(input=fc, label=label)
    loss = fluid.layers.mean(loss)
    return loss