示例#1
0
def ResNet_V1_beta_block(scope, base_depth, num_units, stride):
    return resnet_v1_utils.Block(scope, Bottleneck, [{
        'depth': base_depth * 4,
        'depth_bottleneck': base_depth,
        'stride': 1,
        'unit_rate': 1
    }] * (num_units - 1) + [{
        'depth': base_depth * 4,
        'depth_bottleneck': base_depth,
        'stride': stride,
        'unit_rate': 1
    }])
示例#2
0
def ResNetV1Beta_18(num_classes=None,
                    is_training=None,
                    global_pool=False,
                    base_only=False,
                    min_base_depth=8,
                    depth_multiplier=1,
                    root_depth_multiplier=0.25,
                    output_stride=None,
                    extract_blocks=None,
                    input_shape=None,
                    input_tensor=None,
                    multi_grid=None,
                    name='resnet_v1_18'):
    if multi_grid is None:
        multi_grid = _DEFAULT_MULTI_GRID_RESNET_18
    elif len(multi_grid) != 2:
        raise ValueError("Expect multi_grid to have length 2.")
    depth_func = lambda d: max(int(d * depth_multiplier), min_base_depth)
    block4_args = []
    for rate in multi_grid:
        block4_args.append({
            'depth': depth_func(512),
            'stride': 1,
            'unit_rate': rate
        })

    blocks = [
        ResNet_V1_small_beta_block('block1',
                                   base_depth=depth_func(64),
                                   num_units=2,
                                   stride=2),
        ResNet_V1_small_beta_block('block2',
                                   base_depth=depth_func(128),
                                   num_units=2,
                                   stride=2),
        ResNet_V1_small_beta_block('block3',
                                   base_depth=depth_func(256),
                                   num_units=2,
                                   stride=2),
        resnet_v1_utils.Block('block4', BasicBlock, block4_args)
    ]
    return _ResNetV1Beta(
        blocks=blocks,
        num_classes=num_classes,
        is_training=is_training,
        global_pool=global_pool,
        base_only=base_only,
        root_block=resnet_v1_utils.root_block(root_depth_multiplier),
        output_stride=output_stride,
        extract_blocks=extract_blocks,
        input_shape=input_shape,
        input_tensor=input_tensor,
        name=name)
示例#3
0
def ResNetV1Beta_101(num_classes=None,
                     is_training=None,
                     base_only=False,
                     global_pool=False,
                     min_base_depth=8,
                     depth_multiplier=1,
                     output_stride=None,
                     extract_blocks=None,
                     input_shape=None,
                     input_tensor=None,
                     multi_grid=None,
                     name='resnet_v1_101'):
    if multi_grid is None:
        multi_grid = _DEFAULT_MULTI_GRID
    elif len(multi_grid) != 3:
        raise ValueError("Expect multi_grid to have length 3.")
    depth_func = lambda d: max(int(d * depth_multiplier), min_base_depth)
    blocks = [
        ResNet_V1_beta_block('block1',
                             base_depth=depth_func(64),
                             num_units=3,
                             stride=2),
        ResNet_V1_beta_block('block2',
                             base_depth=depth_func(128),
                             num_units=4,
                             stride=2),
        ResNet_V1_beta_block('block3',
                             base_depth=depth_func(256),
                             num_units=23,
                             stride=2),
        resnet_v1_utils.Block('block4', Bottleneck,
                              [{
                                  'depth': 2048,
                                  'depth_bottleneck': depth_func(512),
                                  'stride': 1,
                                  'unit_rate': rate
                              } for rate in multi_grid])
    ]
    return _ResNetV1Beta(blocks=blocks,
                         num_classes=num_classes,
                         is_training=is_training,
                         base_only=base_only,
                         global_pool=global_pool,
                         root_block=resnet_v1_utils.root_block(),
                         output_stride=output_stride,
                         extract_blocks=extract_blocks,
                         input_shape=input_shape,
                         input_tensor=input_tensor,
                         name=name)
示例#4
0
def ResNet_V1_small_beta_block(scope, base_depth, num_units, stride):
    block_args = []
    for _ in range(num_units - 1):
        block_args.append({'depth': base_depth, 'stride': 1, 'unit_rate': 1})
    block_args.append({'depth': base_depth, 'stride': stride, 'unit_rate': 1})
    return resnet_v1_utils.Block(scope, BasicBlock, block_args)