def create_part2(data, num_class, workspace=512): # group4 # g4_1 = create_convrelu_unit(data, "conv4_1", 512, lr_type="alex", workspace=workspace) g4_2 = create_convrelu_unit(data, "conv4_2", 512, lr_type="alex", workspace=workspace) g4_3 = create_convrelu_unit(g4_2, "conv4_3", 512, lr_type="alex", workspace=workspace) pool4 = syms.maxpool(g4_3, 2, 0, 2, pooling_convention='valid') # group5 g5_1 = create_convrelu_unit(pool4, "conv5_1", 512, lr_type="alex", workspace=workspace) g5_2 = create_convrelu_unit(g5_1, "conv5_2", 512, lr_type="alex", workspace=workspace) g5_3 = create_convrelu_unit(g5_2, "conv5_3", 512, lr_type="alex", workspace=workspace) pool5 = syms.maxpool(g5_3, 2, 0, 2, pooling_convention='valid') fl = mx.sym.flatten(pool5) 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_part1(data, workspace=512): g1_1 = create_convrelu_unit(data, "conv1_1", 64, lr_type="alex", workspace=workspace) g1_2 = create_convrelu_unit(g1_1, "conv1_2", 64, lr_type="alex", workspace=workspace) pool1 = syms.maxpool(g1_2, 2, 0, 2, pooling_convention='valid') # group2 g2_1 = create_convrelu_unit(pool1, "conv2_1", 128, lr_type="alex", workspace=workspace) g2_2 = create_convrelu_unit(g2_1, "conv2_2", 128, lr_type="alex", workspace=workspace) pool2 = syms.maxpool(g2_2, 2, 0, 2, pooling_convention='valid') # group3 g3_1 = create_convrelu_unit(pool2, "conv3_1", 256, lr_type="alex", workspace=workspace) g3_2 = create_convrelu_unit(g3_1, "conv3_2", 256, lr_type="alex", workspace=workspace) g3_3 = create_convrelu_unit(g3_2, "conv3_3", 256, lr_type="alex", workspace=workspace) pool3 = syms.maxpool(g3_3, 2, 0, 2, pooling_convention='valid') g4_1 = create_convrelu_unit(pool3, "conv4_1", 512, lr_type="alex", workspace=workspace) return g4_1
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
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
def create_low_feat(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, 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) return g3_3
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_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
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
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]
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_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
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
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
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