Beispiel #1
0
def resnet_v1_101(inputs, output_stride=8, is_training=True):

    blocks = [
        resnet_v1.resnet_v1_block('block1',
                                  base_depth=64,
                                  num_units=3,
                                  stride=1),
        resnet_v1.resnet_v1_block('block2',
                                  base_depth=128,
                                  num_units=4,
                                  stride=2),
        resnet_v1.resnet_v1_block('block3',
                                  base_depth=256,
                                  num_units=23,
                                  stride=2),
        resnet_v1.resnet_v1_block('block4',
                                  base_depth=512,
                                  num_units=3,
                                  stride=2),
    ]

    with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with tf.variable_scope('resnet_v1_101', 'resnet_v1', [inputs]) as sc:
            end_points_collection = sc.original_name_scope + '_end_points'
            with slim.arg_scope([
                    slim.conv2d, resnet_v1.bottleneck,
                    resnet_utils.stack_blocks_dense
            ],
                                outputs_collections=end_points_collection):
                with slim.arg_scope([slim.batch_norm],
                                    is_training=is_training):
                    net = inputs
                    output_stride /= 4
                    net = resnet_utils.conv2d_same(net,
                                                   64,
                                                   7,
                                                   stride=2,
                                                   scope='conv1')
                    net = slim.max_pool2d(net, [2, 2], stride=2, scope='pool1')
                    net = resnet_utils.stack_blocks_dense(
                        net, blocks, output_stride)
                    # Convert end_points_collection into a dictionary of end_points.
                    end_points = slim.utils.convert_collection_to_dict(
                        end_points_collection)

        outputs = {}
        outputs['conv1'] = end_points['resnet_v1_101/conv1']
        outputs['conv2'] = end_points['resnet_v1_101/block1']
        outputs['conv3'] = end_points['resnet_v1_101/block2']
        outputs['conv4'] = end_points['resnet_v1_101/block3']
        outputs['conv5'] = end_points['resnet_v1_101/block4']

    return outputs
Beispiel #2
0
def resnet_v1_50(inputs, is_training=True):

    blocks = [
        resnet_v1.resnet_v1_block('block1',
                                  base_depth=64,
                                  num_units=3,
                                  stride=2),
        resnet_v1.resnet_v1_block('block2',
                                  base_depth=128,
                                  num_units=4,
                                  stride=2),
        resnet_v1.resnet_v1_block('block3',
                                  base_depth=256,
                                  num_units=6,
                                  stride=2),
        resnet_v1.resnet_v1_block('block4',
                                  base_depth=512,
                                  num_units=3,
                                  stride=1),
    ]

    with slim.arg_scope(resnet_v1.resnet_arg_scope()):
        with tf.variable_scope('resnet_v1_50', 'resnet_v1', [inputs]):
            with slim.arg_scope([
                    slim.conv2d, resnet_v1.bottleneck,
                    resnet_utils.stack_blocks_dense
            ]):
                with slim.arg_scope([slim.batch_norm],
                                    is_training=is_training):
                    net = inputs
                    net = resnet_utils.conv2d_same(net,
                                                   64,
                                                   7,
                                                   stride=2,
                                                   scope='conv1')
                    net = slim.max_pool2d(net, [2, 2], stride=2, scope='pool1')
                    net = resnet_utils.stack_blocks_dense(net, blocks)
                    net = tf.reduce_mean(net, [1, 2],
                                         name='pool5',
                                         keepdims=True)

    return net