Ejemplo n.º 1
0
def mobilenet_ssd(image, L2_reg, is_training=True):

    assert 'MobilenetV2' in cfg.MODEL.net_structure

    if cfg.TRAIN.lock_basenet_bn:
        arg_scope = training_scope(weight_decay=L2_reg, is_training=False)
    else:
        arg_scope = training_scope(weight_decay=L2_reg,
                                   is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):
        # _,endpoint = mobilenet_v2_050(image,is_training=is_training,base_only=True,finegrain_classification_mode=False)
        _, endpoint = mobilenet_v2_140(image,
                                       is_training=is_training,
                                       base_only=True,
                                       finegrain_classification_mode=False)

    for k, v in endpoint.items():
        print('mobile backbone output:', k, v)

    mobilebet_fms = [
        endpoint['layer_5/expansion_output'],
        endpoint['layer_8/expansion_output'],
        endpoint['layer_15/expansion_output'], endpoint['layer_18/output']
    ]

    print('mobile backbone output:', mobilebet_fms)
    with slim.arg_scope(
            resnet_arg_scope(weight_decay=L2_reg, bn_is_training=is_training)):

        net = slim.conv2d(mobilebet_fms[-1],
                          128, [1, 1],
                          stride=1,
                          activation_fn=tf.nn.relu,
                          scope='extra_conv_1_1')
        net = slim.conv2d(net,
                          256, [3, 3],
                          stride=2,
                          activation_fn=tf.nn.relu,
                          scope='extra_conv_1_2')
        mobilebet_fms.append(net)
        net = slim.conv2d(net,
                          128, [1, 1],
                          stride=1,
                          activation_fn=tf.nn.relu,
                          scope='extra_conv_2_1')
        net = slim.conv2d(net,
                          256, [3, 3],
                          stride=2,
                          activation_fn=tf.nn.relu,
                          scope='extra_conv_2_2')
        mobilebet_fms.append(net)
        print('extra backbone output:', mobilebet_fms)
        if cfg.MODEL.fpn:
            enhanced_fms = create_fem_net(mobilebet_fms, L2_reg, is_training)
        else:
            enhanced_fms = None
    return mobilebet_fms, enhanced_fms
Ejemplo n.º 2
0
def mobilenetv3_large(image, is_training=True):

    arg_scope = training_scope(weight_decay=cfg.TRAIN.weight_decay_factor,
                               is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):

        _, endpoints = mobilnet_v3.large(image,
                                         depth_multiplier=0.75,
                                         is_training=is_training,
                                         base_only=True,
                                         finegrain_classification_mode=False)

        # end_feature=slim.separable_conv2d(endpoints['layer_16/output'],
        #                                   512,
        #                                   [3, 3],
        #                                   stride=1,
        #                                   scope='mbntev3_extra_conv')

        # for k,v in endpoints.items():
        #     print('mobile backbone output:',k,v)
        #
        mobilebet_fms = [
            endpoints['layer_5/expansion_output'],
            endpoints['layer_8/expansion_output'],
            endpoints['layer_14/expansion_output'], _
        ]

    return mobilebet_fms
Ejemplo n.º 3
0
def mobilenetv3_ssd(image, is_training=True):

    arg_scope = training_scope(weight_decay=cfg.TRAIN.weight_decay_factor,
                               is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):
        _, endpoint = mobilnet_v3.small_minimalistic(
            image,
            is_training=is_training,
            base_only=True,
            finegrain_classification_mode=False)

        for k, v in endpoint.items():
            print('mobile backbone output:', k, v)

        mobilebet_fms = [
            endpoint['layer_4/output'], endpoint['layer_8/output'],
            endpoint['layer_12/output']
        ]

        if cfg.MODEL.fpn:
            mobilebet_fms = create_fpn_net(mobilebet_fms,
                                           dims_list=cfg.MODEL.fpn_dims)

    return mobilebet_fms
def mobilenetv3_small_minimalistic(image, is_training=True):

    arg_scope = training_scope(weight_decay=cfg.TRAIN.weight_decay_factor,
                               is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):

        final_feature, endpoints = mobilnet_v3.small_minimalistic(
            image,
            depth_multiplier=1.0,
            is_training=is_training,
            base_only=True,
            finegrain_classification_mode=False)

        x = tf.reduce_mean(final_feature, axis=[1, 2], keep_dims=True)

        x = slim.dropout(x, 0.5)

        x = slim.conv2d(x,
                        num_outputs=cfg.MODEL.cls,
                        kernel_size=[1, 1],
                        stride=1,
                        padding='VALID',
                        activation_fn=None,
                        normalizer_fn=None,
                        scope='classifier/0')

    x = tf.squeeze(x, axis=1)
    x = tf.squeeze(x, axis=1)
    x = tf.identity(x, name='cls_output')
    return x
def mobilenetv3_large_detection(image, is_training=True):

    arg_scope = training_scope(weight_decay=cfg.TRAIN.weight_decay_factor,
                               is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):

        _, endpoints = mobilnet_v3.large(image,
                                         depth_multiplier=0.75,
                                         is_training=is_training,
                                         base_only=True,
                                         finegrain_classification_mode=False)

        for k, v in endpoints.items():
            print('mobile backbone output:', k, v)

        extern_conv = slim.conv2d(_,
                                  480, [1, 1],
                                  stride=1,
                                  padding='SAME',
                                  activation_fn=hard_swish,
                                  scope='extern1')

        print(extern_conv)
        mobilebet_fms = [
            endpoints['layer_5/expansion_output'],
            endpoints['layer_7/expansion_output'],
            endpoints['layer_13/output'], extern_conv
        ]

    return mobilebet_fms
def mobilenetv3_small_minimalistic(image, is_training=True):

    arg_scope = training_scope(weight_decay=cfg.TRAIN.weight_decay_factor,
                               is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):
        if cfg.DATA.channel == 1:
            if cfg.MODEL.global_stride == 8:
                stride = 2
            else:
                stride = 1
            image = slim.separable_conv2d(image,
                                          3, [3, 3],
                                          stride=stride,
                                          padding='SAME',
                                          scope='preconv')

        final_feature, endpoints = mobilnet_v3.small_minimalistic(
            image,
            depth_multiplier=1.0,
            is_training=is_training,
            base_only=True,
            finegrain_classification_mode=False)

        extern_conv = slim.separable_conv2d(final_feature,
                                            128, [3, 3],
                                            stride=2,
                                            padding='SAME',
                                            scope='extern1')
        extern_conv = slim.separable_conv2d(extern_conv,
                                            96, [3, 3],
                                            padding='SAME',
                                            scope='extern2')
        extern_conv = slim.separable_conv2d(extern_conv,
                                            128, [3, 3],
                                            padding='SAME',
                                            scope='extern3')

        for k, v in endpoints.items():
            print('mobile backbone output:', k, v)

        mobilebet_fms = [
            endpoints['layer_3/expansion_output'],
            endpoints['layer_5/expansion_output'],
            endpoints['layer_9/expansion_output'],
            #final_feature,
            extern_conv
        ]

    return mobilebet_fms
def training_scope(**kwargs):
    """Defines MobilenetV2 training scope.
  Usage:
     with tf.contrib.slim.arg_scope(mobilenet_v2.training_scope()):
       logits, endpoints = mobilenet_v2.mobilenet(input_tensor)
  with slim.
  Args:
    **kwargs: Passed to mobilenet.training_scope. The following parameters
    are supported:
      weight_decay- The weight decay to use for regularizing the model.
      stddev-  Standard deviation for initialization, if negative uses xavier.
      dropout_keep_prob- dropout keep probability
      bn_decay- decay for the batch norm moving averages.
  Returns:
    An `arg_scope` to use for the mobilenet v2 model.
  """
    return lib.training_scope(**kwargs)
Ejemplo n.º 8
0
def mobilenet_ssd(image,L2_reg,is_training=True):

    arg_scope = training_scope(weight_decay=L2_reg, is_training=is_training)

    with tf.contrib.slim.arg_scope(arg_scope):
        _,endpoint = mobilenet_v2_035(image,is_training=is_training,base_only=True,finegrain_classification_mode=False)

        for k,v in endpoint.items():
            print('mobile backbone output:',k,v)

        mobilebet_fms=[
                       endpoint['layer_8/expansion_output'],
                       endpoint['layer_15/expansion_output'],
                       endpoint['layer_18/output']]

        if cfg.MODEL.fpn:
            mobilebet_fms=create_fpn_net(mobilebet_fms,dims_list=cfg.MODEL.fpn_dims)

    return mobilebet_fms