def create_CRP(data, num_filter, name, workspace=512, lr_type="alex10"):
    relu1 = syms.relu(data)
    c1 = syms.conv(relu1, kernel=3, pad=1, num_filter=num_filter, name=name+"_conv1", no_bias=True, workspace=workspace, lr_type=lr_type)
    p1 = syms.maxpool(c1, kernel=5, pad=2)

    c2 = syms.conv(p1, kernel=3, pad=1, num_filter=num_filter, name=name+"_conv2", no_bias=True, workspace=workspace, lr_type=lr_type)
    p2 = syms.maxpool(c2, kernel=5, pad=2)
    
    c3 = syms.conv(p2, kernel=3, pad=1, num_filter=num_filter, name=name+"_conv3", no_bias=True, workspace=workspace, lr_type=lr_type)
    p3 = syms.maxpool(c3, kernel=5, pad=2)
    
    c4 = syms.conv(p3, kernel=3, pad=1, num_filter=num_filter, name=name+"_conv4", no_bias=True, workspace=workspace, lr_type=lr_type)
    p4 = syms.maxpool(c4, kernel=5, pad=2)
    
    return relu1+p1+p2+p3+p4
Beispiel #2
0
def create_block(data,
                 name,
                 num_filter,
                 kernel,
                 pad=0,
                 stride=1,
                 dilate=1,
                 workspace=512,
                 use_global_stats=True,
                 for_g=False,
                 lr_type="alex"):
    res_name = "res" + name
    bn_name = "bn" + name
    if for_g:
        res_name += "_g"
        bn_name += "_g"
    res = syms.conv(data=data,
                    name=res_name,
                    num_filter=num_filter,
                    pad=pad,
                    kernel=kernel,
                    stride=stride,
                    dilate=dilate,
                    no_bias=True,
                    workspace=workspace,
                    lr_type=lr_type)
    bn = syms.bn(res,
                 name=bn_name,
                 use_global_stats=use_global_stats,
                 lr_type=lr_type)
    return bn
Beispiel #3
0
def create_classifier(data, class_num, lr_type="alex10", workspace=512):
    fc8_SEC = syms.conv(data,
                        "fc8_SEC",
                        num_filter=class_num,
                        lr_type=lr_type,
                        workspace=workspace)
    return fc8_SEC
def create_refine_block(input1, name, num_filter1, num_filter2=None, input2=None, workspace=512, lr_type="alex10"):
    rcu1 = create_big_RCU(input1, num_filter=num_filter1, name=name+"_rcu1", workspace=workspace, lr_type=lr_type)
    if input2 is not None:
        assert num_filter2 is not None
        rcu2 = create_big_RCU(input2, num_filter=num_filter2, name=name+"_rcu2", workspace=workspace, lr_type=lr_type)
        adapt1 = syms.conv(data=rcu1, kernel=3, pad=1, num_filter=num_filter2, name=name+"_adapt1", workspace=workspace, no_bias=True, lr_type=lr_type)
        adapt2 = syms.conv(data=rcu2, kernel=3, pad=1, num_filter=num_filter2, name=name+"_adapt2", workspace=workspace, no_bias=True, lr_type=lr_type)

        up1 = syms.upsample(adapt1, name=name+"_up1", scale=2, num_filter=num_filter2)
        res = up1+adapt2
        crp = create_CRP(res, name=name+"_crp", num_filter=num_filter2, workspace=workspace, lr_type=lr_type)
        output_rcu = create_RCU(crp, num_filter=num_filter2, name=name+"_outputrcu", workspace=workspace, lr_type=lr_type)
        return output_rcu
    else:
        crp = create_CRP(rcu1, name=name+"_crp", num_filter=num_filter1, workspace=workspace, lr_type=lr_type)
        rcu2 = create_RCU(crp, num_filter=num_filter1, name=name+"_outputrcu", workspace=workspace, lr_type=lr_type)
        return rcu2
Beispiel #5
0
def create_classifier(data, class_num, lr_type="alex10", workspace=512):
    CAM_pool = syms.avgpool(data, global_pool=True)
    CAM_fc = syms.conv(CAM_pool,
                       "scores",
                       num_filter=class_num,
                       lr_type=lr_type,
                       workspace=workspace)
    flattened = mx.sym.flatten(CAM_fc)
    return flattened
Beispiel #6
0
def create_part1(data, workspace=512, use_global_stats=True, lr_type="alex"):
    data = mx.symbol.Variable(name="data")
    conv1 = syms.conv(data,
                      name="conv1",
                      num_filter=64,
                      pad=3,
                      kernel=7,
                      stride=2,
                      workspace=workspace,
                      lr_type=lr_type)
    bn = syms.bn(conv1,
                 name="bn_conv1",
                 use_global_stats=use_global_stats,
                 lr_type=lr_type)
    relu = syms.relu(bn)
    pool1 = syms.maxpool(relu, kernel=3, stride=2, pad=1)

    res2a = create_big_block(pool1,
                             "2a",
                             64,
                             256,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res2b = create_big_block(res2a,
                             "2b",
                             64,
                             256,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res2c = create_big_block(res2b,
                             "2c",
                             64,
                             256,
                             workspace=workspace,
                             use_global_stats=use_global_stats)
    res3a = create_big_block(res2c,
                             "3a",
                             128,
                             512,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res3b = create_big_block(res3a,
                             "3b",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)

    return res3b
Beispiel #7
0
def create_aspp_block(data, dilate, name, workspace=512):
    conv1 = syms.conv(data,
                      name="fc6_" + name,
                      num_filter=1024,
                      pad=dilate,
                      kernel=3,
                      stride=1,
                      dilate=dilate,
                      workspace=workspace,
                      lr_type="alex")
    relu1 = syms.relu(conv1)
    fc = syms.conv(relu1,
                   name="fc7_" + name,
                   num_filter=1024,
                   kernel=1,
                   workspace=workspace,
                   lr_type="alex")
    fc_relu = syms.relu(fc)
    return fc_relu
Beispiel #8
0
def create_main(class_num, workspace=512, use_global_stats=True, lr_type="alex"):
    data = mx.symbol.Variable(name="data")

    conv1 = syms.conv(data, name="conv1", num_filter=64, pad=3, kernel=7, stride=2, workspace=workspace, lr_type=lr_type)
    bn = syms.bn(conv1, name="bn_conv1", use_global_stats=use_global_stats, lr_type=lr_type)
    relu = syms.relu(bn)
    pool1 = syms.maxpool(relu, kernel=3, stride=2, pad=1)

    res2a = create_big_block(pool1, "2a", 64, 256, identity_map=False, workspace=workspace
                             , use_global_stats=use_global_stats, lr_type=lr_type)
    res2b = create_big_block(res2a, "2b", 64, 256, workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res2c = create_big_block(res2b, "2c", 64, 256, workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res3a = create_big_block(res2c, "3a", 128, 512, stride=2,identity_map=False, workspace=workspace,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res3b = create_big_block(res3a, "3b", 128, 512, workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res3c = create_big_block(res3b, "3c", 128, 512, workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res3d = create_big_block(res3c, "3d", 128, 512, workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res4a = create_big_block(res3d, "4a", 256, 1024, stride=1, identity_map=False, pad=2, dilate=2,
                             workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res4b = create_big_block(res4a, "4b", 256, 1024, workspace=workspace, pad=2, dilate=2,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res4c = create_big_block(res4b, "4c", 256, 1024, workspace=workspace, pad=2, dilate=2,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res4d = create_big_block(res4c, "4d", 256, 1024, workspace=workspace, pad=2, dilate=2,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res4e = create_big_block(res4d, "4e", 256, 1024, workspace=workspace, pad=2, dilate=2,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res4f = create_big_block(res4e, "4f", 256, 1024, workspace=workspace, pad=2, dilate=2,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res5a = create_big_block(res4f, "5a", 512, 2048, stride=1, identity_map=False, pad=4, dilate=4,
                             workspace=workspace, use_global_stats=use_global_stats, lr_type=lr_type)
    res5b = create_big_block(res5a, "5b", 512, 2048, workspace=workspace, pad=4, dilate=4,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    res5c = create_big_block(res5b, "5c", 512, 2048, workspace=workspace, pad=4, dilate=4,
                             use_global_stats=use_global_stats, lr_type=lr_type)
    new_conv1 = syms.conv(res5c, name="new_conv1", num_filter=512, pad=12, kernel=3, dilate=12,
                          workspace=workspace, lr_type="alex10")
    new_relu1 = syms.relu(new_conv1)
    dp1 = syms.dropout(new_relu1)
    fc = syms.conv(dp1, name="fc", num_filter=512, workspace=workspace, lr_type="alex10")
    fc_relu = syms.relu(fc)
    net = syms.conv(fc_relu, name="score", num_filter=class_num, workspace=workspace, lr_type="alex10")
    return net
Beispiel #9
0
def create_body(data, lr_type="alex", workspace=512):

    # group1
    g1_1 = create_convrelu_unit(data, "conv1_1", 64, lr_type=lr_type, workspace=workspace)
    g1_2 = create_convrelu_unit(g1_1, "conv1_2", 64, lr_type=lr_type, workspace=workspace)
    pool1 = syms.maxpool(g1_2, 3, 1, 2)

    # group2
    g2_1 = create_convrelu_unit(pool1, "conv2_1", 128, lr_type=lr_type, workspace=workspace)
    g2_2 = create_convrelu_unit(g2_1, "conv2_2", 128, lr_type=lr_type, workspace=workspace)
    pool2 = syms.maxpool(g2_2, 3, 1, 2)

    # group3
    g3_1 = create_convrelu_unit(pool2, "conv3_1", 256, lr_type=lr_type, workspace=workspace)
    g3_2 = create_convrelu_unit(g3_1, "conv3_2", 256, lr_type=lr_type, workspace=workspace)
    g3_3 = create_convrelu_unit(g3_2, "conv3_3", 256, lr_type=lr_type, workspace=workspace)
    pool3 = syms.maxpool(g3_3, 3, 1, 2)

    # group4
    g4_1 = create_convrelu_unit(pool3, "conv4_1", 512, lr_type=lr_type, workspace=workspace)
    g4_2 = create_convrelu_unit(g4_1, "conv4_2", 512, lr_type=lr_type, workspace=workspace)
    g4_3 = create_convrelu_unit(g4_2, "conv4_3", 512, lr_type=lr_type, workspace=workspace)
    pool4 = syms.maxpool(g4_3, 3, 1, 1)

    # group5
    g5_1 = create_convrelu_unit(pool4, "conv5_1", 512, lr_type=lr_type, dilate=2, pad=2, workspace=workspace)
    g5_2 = create_convrelu_unit(g5_1, "conv5_2", 512, lr_type=lr_type, dilate=2, pad=2, workspace=workspace)
    g5_3 = create_convrelu_unit(g5_2, "conv5_3", 512, lr_type=lr_type, dilate=2, pad=2, workspace=workspace)

    pool5 = syms.maxpool(g5_3, 3, 1, 1)
    pool5a = syms.avgpool(pool5, 3, 1, 1)

    # group6
    conv6 = syms.conv(pool5a, "fc6", 1024, kernel=3, lr_type=lr_type, dilate=12, pad=12, workspace=workspace)
    relu6 = syms.relu(conv6)

    # group7
    conv7 = syms.conv(relu6, "fc7", 1024, lr_type=lr_type, workspace=workspace)
    relu7 = syms.relu(conv7)

    return relu7
def create_main(data, class_num, workspace=512, lr_type="alex10"):
    outputs = create_res101_main(data, workspace=workspace)
    
    outputs = outputs[::-1]

    refine1_adapt1 = syms.conv(data=outputs[0], kernel=3, pad=1, num_filter=512, name="refine1_input_adapt1", no_bias=True, workspace=workspace, lr_type=lr_type)
    refine_block1 = create_refine_block(refine1_adapt1, name="refine1", num_filter1=512, workspace=workspace, lr_type=lr_type)

    refine2_adapt2 = syms.conv(data=outputs[1], kernel=3, pad=1, num_filter=256, name="refine2_input_adapt2", no_bias=True, workspace=workspace, lr_type=lr_type)
    refine_block2 = create_refine_block(input1=refine_block1, input2=refine2_adapt2, num_filter1=512, num_filter2=256, name="refine2", workspace=workspace, lr_type=lr_type)

    refine3_adapt2 = syms.conv(data=outputs[2], kernel=3, pad=1, num_filter=256, name="refine3_input_adapt2", no_bias=True, workspace=workspace, lr_type=lr_type)
    refine_block3 = create_refine_block(input1=refine_block2, input2=refine3_adapt2, num_filter1=256, num_filter2=256, name="refine3", workspace=workspace, lr_type=lr_type)

    refine4_adapt2 = syms.conv(data=outputs[3], kernel=3, pad=1, num_filter=256, name="refine4_input_adapt2", no_bias=True, workspace=workspace, lr_type=lr_type)
    refine_block4 = create_refine_block(input1=refine_block3, input2=refine4_adapt2, num_filter1=256, num_filter2=256, name="refine4", workspace=workspace, lr_type=lr_type)

    final_rcu = create_big_RCU(refine_block4, num_filter=256, name="final_rcu1" , workspace=workspace, lr_type=lr_type)
    dp = syms.dropout(data=final_rcu, p=0.5)
    classifier = syms.conv(data=dp, kernel=3, num_filter=class_num, name="score", workspace=workspace, pad=1, lr_type=lr_type)
    return classifier
Beispiel #11
0
def create_body(lr_type="alex", workspace=512):
    data = mx.symbol.Variable(name="data")
    # group1
    g1_1 = create_convrelu_unit(data, "conv1_1", 64, lr_type=lr_type, workspace=workspace)
    g1_2 = create_convrelu_unit(g1_1, "conv1_2", 64, lr_type=lr_type, workspace=workspace)
    pool1 = syms.maxpool(g1_2, 3, 1, 2, pooling_convention="valid")

    # group2
    g2_1 = create_convrelu_unit(pool1, "conv2_1", 128, lr_type=lr_type, workspace=workspace)
    g2_2 = create_convrelu_unit(g2_1, "conv2_2", 128, lr_type=lr_type, workspace=workspace)
    pool2 = syms.maxpool(g2_2, 3, 1, 2, pooling_convention="valid")

    # group3
    g3_1 = create_convrelu_unit(pool2, "conv3_1", 256, lr_type=lr_type, workspace=workspace)
    g3_2 = create_convrelu_unit(g3_1, "conv3_2", 256, lr_type=lr_type, workspace=workspace)
    g3_3 = create_convrelu_unit(g3_2, "conv3_3", 256, lr_type=lr_type, workspace=workspace)
    pool3 = syms.maxpool(g3_3, 3, 1, 2, pooling_convention="valid")

    # group4
    g4_1 = create_convrelu_unit(pool3, "conv4_1", 512, lr_type=lr_type, workspace=workspace)
    g4_2 = create_convrelu_unit(g4_1, "conv4_2", 512, lr_type=lr_type, workspace=workspace)
    g4_3 = create_convrelu_unit(g4_2, "conv4_3", 512, lr_type=lr_type, workspace=workspace)


    # group5
    g5_1 = create_convrelu_unit(g4_3, "conv5_1", 512, lr_type=lr_type, workspace=workspace)
    g5_2 = create_convrelu_unit(g5_1, "conv5_2", 512, lr_type=lr_type, workspace=workspace)
    g5_3 = create_convrelu_unit(g5_2, "conv5_3", 512, lr_type=lr_type, workspace=workspace)

    # group6
    conv6 = syms.conv(g5_3, "conv6_CAM", 1024, pad=1, kernel=3, lr_type="alex10", workspace=workspace)
    relu6 = syms.relu(conv6)
    relu6_dp = syms.dropout(relu6, 0.5)

    # group7
    conv7 = syms.conv(relu6_dp, "conv7_CAM", 1024, pad=1, kernel=3, lr_type="alex10", workspace=workspace)
    relu7 = syms.relu(conv7)
    relu7_dp = syms.dropout(relu7, 0.5)

    return relu7_dp
Beispiel #12
0
def create_convrelu_unit(data,
                         name,
                         num_filter,
                         lr_type="alex",
                         pad=1,
                         kernel=3,
                         stride=1,
                         workspace=512):
    conv = syms.conv(data,
                     name=name,
                     num_filter=num_filter,
                     pad=pad,
                     kernel=kernel,
                     stride=stride,
                     workspace=workspace,
                     lr_type=lr_type)
    relu = syms.relu(conv)
    return relu
def create_res101_main(data, workspace=512, use_global_stats=True):
    conv1 = syms.conv(data, name="conv1", num_filter=64, pad=3, kernel=7, stride=2, workspace=workspace, no_bias=True)
    bn = syms.bn(conv1, name="bn_conv1", use_global_stats=use_global_stats)
    relu = syms.relu(bn)
    pool1 = syms.maxpool(relu, kernel=3, stride=2, pad=1)

    res2a = create_big_block(pool1, "2a", 64, 256, identity_map=False, workspace=workspace, use_global_stats=use_global_stats)
    res2b = create_big_block(res2a, "2b", 64, 256, workspace=workspace, use_global_stats=use_global_stats)
    res2c = create_big_block(res2b, "2c", 64, 256, workspace=workspace, use_global_stats=use_global_stats)
    res3a = create_big_block(res2c, "3a", 128, 512, stride=2, identity_map=False, workspace=workspace, use_global_stats=use_global_stats)
    res3b1 = create_big_block(res3a, "3b1", 128, 512, workspace=workspace, use_global_stats=use_global_stats)
    res3b2 = create_big_block(res3b1, "3b2", 128, 512, workspace=workspace, use_global_stats=use_global_stats)
    res3b3 = create_big_block(res3b2, "3b3", 128, 512, workspace=workspace, use_global_stats=use_global_stats)

    res4a = create_big_block(res3b3, "4a", 256, 1024, stride=2, identity_map=False, workspace=workspace, use_global_stats=use_global_stats)
    res4b1 = create_big_block(res4a, "4b1", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b2 = create_big_block(res4b1, "4b2", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b3 = create_big_block(res4b2, "4b3", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b4 = create_big_block(res4b3, "4b4", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b5 = create_big_block(res4b4, "4b5", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b6 = create_big_block(res4b5, "4b6", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b7 = create_big_block(res4b6, "4b7", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b8 = create_big_block(res4b7, "4b8", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b9 = create_big_block(res4b8, "4b9", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b10 = create_big_block(res4b9, "4b10", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b11 = create_big_block(res4b10, "4b11", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b12 = create_big_block(res4b11, "4b12", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b13 = create_big_block(res4b12, "4b13", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b14 = create_big_block(res4b13, "4b14", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b15 = create_big_block(res4b14, "4b15", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b16 = create_big_block(res4b15, "4b16", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b17 = create_big_block(res4b16, "4b17", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b18 = create_big_block(res4b17, "4b18", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b19 = create_big_block(res4b18, "4b19", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b20 = create_big_block(res4b19, "4b20", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b21 = create_big_block(res4b20, "4b21", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)
    res4b22 = create_big_block(res4b21, "4b22", 256, 1024, workspace=workspace, use_global_stats=use_global_stats)

    res5a = create_big_block(res4b22, "5a", 512, 2048, stride=2, identity_map=False, workspace=workspace, use_global_stats=use_global_stats)
    res5b = create_big_block(res5a, "5b", 512, 2048, workspace=workspace, use_global_stats=use_global_stats)
    res5c = create_big_block(res5b, "5c", 512, 2048, workspace=workspace, use_global_stats=use_global_stats)

    return [res2c, res3b3, res4b22, res5c]
Beispiel #14
0
def create_seg_part(data,
                    class_num,
                    workspace=512,
                    lr_type="alex",
                    use_global_stats=True):
    res4a = create_big_block(data,
                             "4a",
                             256,
                             1024,
                             stride=1,
                             identity_map=False,
                             pad=2,
                             dilate=2,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4b = create_big_block(res4a,
                             "4b",
                             256,
                             1024,
                             workspace=workspace,
                             pad=2,
                             dilate=2,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4c = create_big_block(res4b,
                             "4c",
                             256,
                             1024,
                             workspace=workspace,
                             pad=2,
                             dilate=2,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4d = create_big_block(res4c,
                             "4d",
                             256,
                             1024,
                             workspace=workspace,
                             pad=2,
                             dilate=2,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4e = create_big_block(res4d,
                             "4e",
                             256,
                             1024,
                             workspace=workspace,
                             pad=2,
                             dilate=2,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4f = create_big_block(res4e,
                             "4f",
                             256,
                             1024,
                             workspace=workspace,
                             pad=2,
                             dilate=2,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5a = create_big_block(res4f,
                             "5a",
                             512,
                             2048,
                             stride=1,
                             identity_map=False,
                             pad=4,
                             dilate=4,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5b = create_big_block(res5a,
                             "5b",
                             512,
                             2048,
                             workspace=workspace,
                             pad=4,
                             dilate=4,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5c = create_big_block(res5b,
                             "5c",
                             512,
                             2048,
                             workspace=workspace,
                             pad=4,
                             dilate=4,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    new_conv1 = syms.conv(res5c,
                          name="new_conv1",
                          num_filter=512,
                          pad=12,
                          kernel=3,
                          dilate=12,
                          workspace=workspace)
    new_relu1 = syms.relu(new_conv1)
    dp1 = syms.dropout(new_relu1)
    fc = syms.conv(dp1, name="fc", num_filter=512, workspace=workspace)
    fc_relu = syms.relu(fc)
    net = syms.conv(fc_relu,
                    name="score",
                    num_filter=class_num,
                    workspace=workspace)
    return net
Beispiel #15
0
def create_g_part(data,
                  class_num,
                  workspace=512,
                  lr_type="alex",
                  use_global_stats=True):
    res4a = create_big_block(data,
                             "4a",
                             256,
                             1024,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res4b = create_big_block(res4a,
                             "4b",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res4c = create_big_block(res4b,
                             "4c",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res4d = create_big_block(res4c,
                             "4d",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res4e = create_big_block(res4d,
                             "4e",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res4f = create_big_block(res4e,
                             "4f",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res5a = create_big_block(res4f,
                             "5a",
                             512,
                             2048,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res5b = create_big_block(res5a,
                             "5b",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)
    res5c = create_big_block(res5b,
                             "5c",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             for_g=True,
                             lr_type=lr_type)

    pool = syms.maxpool(res5c, kernel=1, pad=0, global_pool=True)
    fc1 = syms.conv(data=pool,
                    kernel=1,
                    num_filter=1024,
                    workspace=workspace,
                    name="g_multi_fc1")
    fc1_relu = syms.relu(fc1)
    dp1 = syms.dropout(data=fc1_relu)
    fc2 = syms.conv(data=dp1,
                    kernel=1,
                    num_filter=1024,
                    workspace=workspace,
                    name="g_multi_fc2")
    fc2_relu = syms.relu(fc2)
    dp2 = syms.dropout(data=fc2_relu)
    score = syms.conv(data=dp2,
                      kernel=1,
                      num_filter=class_num,
                      workspace=workspace,
                      name="g_score")
    return score
def create_RCU(data, num_filter, name, workspace=512, lr_type="alex10"):
    relu1 = syms.relu(data)
    res1 = syms.conv(relu1, num_filter=num_filter, name=name+"_b1", kernel=3, pad=1, workspace=workspace, lr_type=lr_type)
    relu2 = syms.relu(res1)
    res2 = syms.conv(relu2, num_filter=num_filter, name=name+"_b2", kernel=3, pad=1, workspace=workspace, no_bias=True, lr_type=lr_type)
    return data+res2
Beispiel #17
0
def create_part2(data,
                 num_class,
                 workspace=512,
                 use_global_stats=True,
                 lr_type="alex"):
    res3c = create_big_block(data,
                             "3c",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res3d = create_big_block(res3c,
                             "3d",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)

    res4a = create_big_block(res3d,
                             "4a",
                             256,
                             1024,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4b = create_big_block(res4a,
                             "4b",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4c = create_big_block(res4b,
                             "4c",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4d = create_big_block(res4c,
                             "4d",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4e = create_big_block(res4d,
                             "4e",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4f = create_big_block(res4e,
                             "4f",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5a = create_big_block(res4f,
                             "5a",
                             512,
                             2048,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5b = create_big_block(res5a,
                             "5b",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5c = create_big_block(res5b,
                             "5c",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)

    adapt = syms.conv(res5c,
                      "adapt",
                      512,
                      kernel=1,
                      lr_type="alex10",
                      workspace=workspace)
    adapt_relu = syms.relu(adapt)

    fl = mx.sym.flatten(adapt_relu)
    fc6 = syms.fullyconnected(fl,
                              num_hidden=1024,
                              name="CAMfc6",
                              lr_type="alex10")
    relu6 = syms.relu(fc6)

    # group7
    fc7 = syms.fullyconnected(relu6,
                              num_hidden=1024,
                              name="CAMfc7",
                              lr_type="alex10")
    relu7 = syms.relu(fc7)

    fc8 = syms.fullyconnected(relu7,
                              num_hidden=num_class,
                              name="CAMfc8",
                              lr_type="alex10")
    return fc8
def create_block(data, name, num_filter, kernel, pad=0, stride=1, dilate=1, workspace=512, use_global_stats=True):
    res = syms.conv(data=data, name="res" + name, num_filter=num_filter, pad=pad, kernel=kernel, stride=stride, dilate=dilate, no_bias=True, workspace=workspace)
    bn = syms.bn(res, name="bn" + name, use_global_stats=use_global_stats)
    return bn
Beispiel #19
0
def create_g_part(data, class_num, lr_type="alex", workspace=512):

    pool3 = syms.maxpool(data, 2, 0, 2, pooling_convention='valid')
    # group4
    g4_1 = create_convrelu_unit(pool3,
                                "conv4_1_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g4_2 = create_convrelu_unit(g4_1,
                                "conv4_2_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g4_3 = create_convrelu_unit(g4_2,
                                "conv4_3_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    pool4 = syms.maxpool(g4_3, 2, 0, 2, pooling_convention='valid')

    # group5
    g5_1 = create_convrelu_unit(pool4,
                                "conv5_1_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g5_2 = create_convrelu_unit(g5_1,
                                "conv5_2_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g5_3 = create_convrelu_unit(g5_2,
                                "conv5_3_g",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)

    pool5 = syms.maxpool(g5_3, 2, 0, 2, pooling_convention='valid')

    # group6
    conv6 = syms.conv(pool5,
                      "fc6_g",
                      1024,
                      kernel=3,
                      lr_type=lr_type,
                      pad=1,
                      workspace=workspace)
    relu6 = syms.relu(conv6)

    # group7
    conv7 = syms.conv(relu6,
                      "fc7_g",
                      1024,
                      lr_type=lr_type,
                      workspace=workspace)
    relu7 = syms.relu(conv7)

    pool = syms.maxpool(relu7, kernel=1, pad=0, global_pool=True)

    fc1 = syms.conv(pool,
                    name="g_multi_fc1",
                    num_filter=1024,
                    workspace=workspace,
                    lr_type="alex10")
    fc1_relu = syms.relu(fc1)
    dp1 = syms.dropout(data=fc1_relu)
    fc2 = syms.conv(dp1,
                    name="g_multi_fc2",
                    num_filter=1024,
                    workspace=workspace,
                    lr_type="alex10")
    fc2_relu = syms.relu(fc2)
    dp2 = syms.dropout(data=fc2_relu)
    g_score = syms.conv(dp2,
                        name="g_score",
                        num_filter=class_num,
                        workspace=workspace,
                        lr_type="alex10")
    return g_score
Beispiel #20
0
def create_body(lr_type="alex", workspace=512, use_global_stats=True):
    data = mx.symbol.Variable(name="data")
    conv1 = syms.conv(data,
                      name="conv1",
                      num_filter=64,
                      pad=3,
                      kernel=7,
                      stride=2,
                      workspace=workspace,
                      lr_type=lr_type)
    bn = syms.bn(conv1,
                 name="bn_conv1",
                 use_global_stats=use_global_stats,
                 lr_type=lr_type)
    relu = syms.relu(bn)
    pool1 = syms.maxpool(relu, kernel=3, stride=2, pad=1)

    res2a = create_big_block(pool1,
                             "2a",
                             64,
                             256,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res2b = create_big_block(res2a,
                             "2b",
                             64,
                             256,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res2c = create_big_block(res2b,
                             "2c",
                             64,
                             256,
                             workspace=workspace,
                             use_global_stats=use_global_stats)
    res3a = create_big_block(res2c,
                             "3a",
                             128,
                             512,
                             stride=2,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res3b = create_big_block(res3a,
                             "3b",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res3c = create_big_block(res3b,
                             "3c",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res3d = create_big_block(res3c,
                             "3d",
                             128,
                             512,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4a = create_big_block(res3d,
                             "4a",
                             256,
                             1024,
                             stride=1,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4b = create_big_block(res4a,
                             "4b",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4c = create_big_block(res4b,
                             "4c",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4d = create_big_block(res4c,
                             "4d",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4e = create_big_block(res4d,
                             "4e",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res4f = create_big_block(res4e,
                             "4f",
                             256,
                             1024,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5a = create_big_block(res4f,
                             "5a",
                             512,
                             2048,
                             stride=1,
                             identity_map=False,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5b = create_big_block(res5a,
                             "5b",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)
    res5c = create_big_block(res5b,
                             "5c",
                             512,
                             2048,
                             workspace=workspace,
                             use_global_stats=use_global_stats,
                             lr_type=lr_type)

    # group6
    conv6 = syms.conv(res5c,
                      "conv6_CAM",
                      1024,
                      pad=1,
                      kernel=3,
                      lr_type="alex10",
                      workspace=workspace)
    relu6 = syms.relu(conv6)
    relu6_dp = syms.dropout(relu6, 0.5)

    # group7
    conv7 = syms.conv(relu6_dp,
                      "conv7_CAM",
                      1024,
                      pad=1,
                      kernel=3,
                      lr_type="alex10",
                      workspace=workspace)
    relu7 = syms.relu(conv7)
    relu7_dp = syms.dropout(relu7, 0.5)

    return relu7_dp
Beispiel #21
0
def create_seg_part(data, class_num, workspace=512, lr_type="alex"):

    pool3 = syms.maxpool(data, 3, 1, 2, pooling_convention='valid')
    # group4
    g4_1 = create_convrelu_unit(pool3,
                                "conv4_1",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g4_2 = create_convrelu_unit(g4_1,
                                "conv4_2",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    g4_3 = create_convrelu_unit(g4_2,
                                "conv4_3",
                                512,
                                lr_type=lr_type,
                                workspace=workspace)
    pool4 = syms.maxpool(g4_3, 3, 1, 1, pooling_convention='valid')

    # group5
    g5_1 = create_convrelu_unit(pool4,
                                "conv5_1",
                                512,
                                lr_type=lr_type,
                                dilate=2,
                                pad=2,
                                workspace=workspace)
    g5_2 = create_convrelu_unit(g5_1,
                                "conv5_2",
                                512,
                                lr_type=lr_type,
                                dilate=2,
                                pad=2,
                                workspace=workspace)
    g5_3 = create_convrelu_unit(g5_2,
                                "conv5_3",
                                512,
                                lr_type=lr_type,
                                dilate=2,
                                pad=2,
                                workspace=workspace)

    pool5 = syms.maxpool(g5_3, 3, 1, 1, pooling_convention='valid')

    c1 = create_aspp_block(pool5, 6, "1")
    c2 = create_aspp_block(pool5, 12, "2")
    c3 = create_aspp_block(pool5, 18, "3")
    c4 = create_aspp_block(pool5, 24, "4")
    merged = c1 + c2 + c3 + c4

    dp1 = syms.dropout(merged)
    fc2 = syms.conv(dp1,
                    name="fc2",
                    num_filter=512,
                    workspace=workspace,
                    lr_type="alex10")
    fc2_relu = syms.relu(fc2)
    dp2 = syms.dropout(fc2_relu)
    net = syms.conv(dp2,
                    name="score",
                    num_filter=class_num,
                    workspace=workspace,
                    lr_type="alex10")
    return net
Beispiel #22
0
def create_main(class_num,
                lr_type_old="alex",
                lr_type_new="alex",
                workspace=512):
    data = mx.symbol.Variable(name="data")
    # group1
    g1_1 = create_convrelu_unit(data,
                                "conv1_1",
                                64,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g1_2 = create_convrelu_unit(g1_1,
                                "conv1_2",
                                64,
                                lr_type=lr_type_old,
                                workspace=workspace)
    pool1 = syms.maxpool(g1_2, 3, 1, 2)

    # group2
    g2_1 = create_convrelu_unit(pool1,
                                "conv2_1",
                                128,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g2_2 = create_convrelu_unit(g2_1,
                                "conv2_2",
                                128,
                                lr_type=lr_type_old,
                                workspace=workspace)
    pool2 = syms.maxpool(g2_2, 3, 1, 2)

    # group3
    g3_1 = create_convrelu_unit(pool2,
                                "conv3_1",
                                256,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g3_2 = create_convrelu_unit(g3_1,
                                "conv3_2",
                                256,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g3_3 = create_convrelu_unit(g3_2,
                                "conv3_3",
                                256,
                                lr_type=lr_type_old,
                                workspace=workspace)
    pool3 = syms.maxpool(g3_3, 3, 1, 2)

    # group4
    g4_1 = create_convrelu_unit(pool3,
                                "conv4_1",
                                512,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g4_2 = create_convrelu_unit(g4_1,
                                "conv4_2",
                                512,
                                lr_type=lr_type_old,
                                workspace=workspace)
    g4_3 = create_convrelu_unit(g4_2,
                                "conv4_3",
                                512,
                                lr_type=lr_type_old,
                                workspace=workspace)
    pool4 = syms.maxpool(g4_3, 3, 1, 1)

    # group5
    g5_1 = create_convrelu_unit(pool4,
                                "conv5_1",
                                512,
                                lr_type=lr_type_old,
                                dilate=2,
                                pad=2,
                                workspace=workspace)
    g5_2 = create_convrelu_unit(g5_1,
                                "conv5_2",
                                512,
                                lr_type=lr_type_old,
                                dilate=2,
                                pad=2,
                                workspace=workspace)
    g5_3 = create_convrelu_unit(g5_2,
                                "conv5_3",
                                512,
                                lr_type=lr_type_old,
                                dilate=2,
                                pad=2,
                                workspace=workspace)

    pool5 = syms.maxpool(g5_3, 3, 1, 1)

    # group6
    conv6 = syms.conv(pool5,
                      "fc6",
                      1024,
                      kernel=3,
                      lr_type=lr_type_old,
                      dilate=4,
                      pad=4,
                      workspace=workspace)
    relu6 = syms.relu(conv6)

    # group7
    conv7 = syms.conv(relu6,
                      "fc7",
                      1024,
                      lr_type=lr_type_old,
                      workspace=workspace)
    relu7 = syms.relu(conv7)

    new1 = syms.conv(relu7,
                     name="new1",
                     num_filter=512,
                     pad=12,
                     kernel=3,
                     dilate=12,
                     workspace=workspace,
                     lr_type="alex10")
    new1_relu = syms.relu(new1)
    dp1 = syms.dropout(new1_relu)
    new2 = syms.conv(dp1,
                     name="new2",
                     num_filter=512,
                     workspace=workspace,
                     lr_type="alex10")
    new2_relu = syms.relu(new2)
    net = syms.conv(new2_relu,
                    name="score",
                    num_filter=class_num,
                    workspace=workspace,
                    lr_type="alex10")

    return net