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
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_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_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
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