Esempio n. 1
0
def mobilenetv2_base(img_batch, is_training=True):

    with slim.arg_scope(mobilenetv2_scope(is_training=is_training, trainable=True)):

        feature_to_crop, endpoints = mobilenet_v2.mobilenet_base(input_tensor=img_batch,
                                                      num_classes=None,
                                                      is_training=False,
                                                      depth_multiplier=1.0,
                                                      scope='MobilenetV2',
                                                      conv_defs=V2_BASE_DEF,
                                                      finegrain_classification_mode=False)

        # feature_to_crop = tf.Print(feature_to_crop, [tf.shape(feature_to_crop)], summarize=10, message='rpn_shape')
        return feature_to_crop
Esempio n. 2
0
def mobilenetv2_head(inputs, is_training=True):
    with slim.arg_scope(
            mobilenetv2_scope(is_training=is_training, trainable=True)):
        net, _ = mobilenet_v2.mobilenet_base(
            input_tensor=inputs,
            num_classes=None,
            is_training=False,
            depth_multiplier=1.0,
            scope='MobilenetV2',
            conv_defs=V2_HEAD_DEF,
            finegrain_classification_mode=True)

        # net = tf.squeeze(net, [1, 2])

        return net
Esempio n. 3
0
def mobilenetv2_base(img_batch, is_training=True):

    with slim.arg_scope(
            mobilenetv2_scope(is_training=is_training, trainable=True)):
        feature_to_crop, endpoints = mobilenet_v2.mobilenet_base(
            input_tensor=img_batch,
            num_classes=None,
            is_training=False,
            depth_multiplier=1.0,
            scope='MobilenetV2',
            conv_defs=V2_BASE_DEF,
            finegrain_classification_mode=False)

        feature_dict = {
            "C3": endpoints['layer_5'],
            'C4': endpoints['layer_8'],
            'C5': endpoints['layer_15']
        }
        pyramid_dict = {}
        with tf.variable_scope('build_pyramid'):
            with slim.arg_scope([slim.conv2d],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY),
                                activation_fn=None,
                                normalizer_fn=None):

                P5 = slim.conv2d(feature_dict['C5'],
                                 num_outputs=256,
                                 kernel_size=[1, 1],
                                 stride=1,
                                 scope='build_P5')

                pyramid_dict['P5'] = P5

                for level in range(4, 2, -1):  # build [P4, P3]

                    pyramid_dict['P%d' % level] = fusion_two_layer(
                        C_i=feature_dict["C%d" % level],
                        P_j=pyramid_dict["P%d" % (level + 1)],
                        scope='build_P%d' % level)
                for level in range(5, 2, -1):
                    pyramid_dict['P%d' % level] = slim.conv2d(
                        pyramid_dict['P%d' % level],
                        num_outputs=256,
                        kernel_size=[3, 3],
                        padding="SAME",
                        stride=1,
                        scope="fuse_P%d" % level)

                p6 = slim.conv2d(
                    pyramid_dict['P5'] if cfgs.USE_P5 else feature_dict['C5'],
                    num_outputs=256,
                    kernel_size=[3, 3],
                    padding="SAME",
                    stride=2,
                    scope='p6_conv')
                pyramid_dict['P6'] = p6

                p7 = tf.nn.relu(p6, name='p6_relu')

                p7 = slim.conv2d(p7,
                                 num_outputs=256,
                                 kernel_size=[3, 3],
                                 padding="SAME",
                                 stride=2,
                                 scope='p7_conv')

                pyramid_dict['P7'] = p7

        # for level in range(7, 1, -1):
        #     add_heatmap(pyramid_dict['P%d' % level], name='Layer%d/P%d_heat' % (level, level))

        return pyramid_dict
def mobilenetv2_base(img_batch, is_training=True):

    with slim.arg_scope(
            mobilenetv2_scope(is_training=is_training, trainable=True)):
        feature_to_crop, endpoints = mobilenet_v2.mobilenet_base(
            input_tensor=img_batch,
            num_classes=None,
            is_training=False,
            depth_multiplier=1.0,
            scope='MobilenetV2',
            conv_defs=V2_BASE_DEF,
            finegrain_classification_mode=False)

        feature_dict = {
            "C3": endpoints['layer_5'],
            'C4': endpoints['layer_8'],
            'C5': endpoints['layer_15']
        }
        pyramid_dict = {}
        with tf.variable_scope('build_pyramid'):
            with slim.arg_scope([slim.conv2d],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY),
                                activation_fn=None,
                                normalizer_fn=None):

                P5 = slim.conv2d(feature_dict['C5'],
                                 num_outputs=256,
                                 kernel_size=[1, 1],
                                 stride=1,
                                 scope='build_P5')

                pyramid_dict['P5'] = P5

                for level in range(4, 2, -1):  # build [P4, P3]

                    pyramid_dict['P%d' % level] = fusion_two_layer(
                        C_i=feature_dict["C%d" % level],
                        P_j=pyramid_dict["P%d" % (level + 1)],
                        scope='build_P%d' % level)
                for level in range(5, 2, -1):
                    pyramid_dict['P%d' % level] = slim.conv2d(
                        pyramid_dict['P%d' % level],
                        num_outputs=256,
                        kernel_size=[3, 3],
                        padding="SAME",
                        stride=1,
                        scope="fuse_P%d" % level)

                p6 = slim.conv2d(
                    pyramid_dict['P5'] if cfgs.USE_P5 else feature_dict['C5'],
                    num_outputs=256,
                    kernel_size=[3, 3],
                    padding="SAME",
                    stride=2,
                    scope='p6_conv')
                pyramid_dict['P6'] = p6

                p7 = tf.nn.relu(p6, name='p6_relu')

                p7 = slim.conv2d(p7,
                                 num_outputs=256,
                                 kernel_size=[3, 3],
                                 padding="SAME",
                                 stride=2,
                                 scope='p7_conv')

                pyramid_dict['P7'] = p7

        print("we are in Pyramid::-======>>>>")
        print(cfgs.LEVEL)
        print("base_anchor_size are: ", cfgs.BASE_ANCHOR_SIZE_LIST)
        print(20 * "__")

        if cfgs.USE_SUPERVISED_MASK:
            mask_list = []
            dot_layer_list = []
            with tf.variable_scope("enrich_semantics"):
                with slim.arg_scope([slim.conv2d],
                                    weights_regularizer=slim.l2_regularizer(
                                        cfgs.WEIGHT_DECAY),
                                    normalizer_fn=None):
                    for i, l_name in enumerate(cfgs.GENERATE_MASK_LIST):
                        G, mask, dot_layer = generate_mask(
                            net=pyramid_dict[l_name],
                            num_layer=cfgs.ADDITION_LAYERS[i],
                            level_name=l_name)
                        # add_heatmap(G, name="MASK/G_%s" % l_name)
                        # add_heatmap(mask, name="MASK/mask_%s" % l_name)

                        # if cfgs.MASK_ACT_FET:
                        #     pyramid_dict[l_name] = pyramid_dict[l_name] * dot_layer
                        dot_layer_list.append(dot_layer)
                        mask_list.append(mask)

            return pyramid_dict, mask_list, dot_layer_list
        else:
            return pyramid_dict