def rpn_cls_net(self, inputs, scope_list, reuse_flag, level):
        rpn_conv2d_3x3 = inputs
        for i in range(4):
            rpn_conv2d_3x3 = slim.conv2d(inputs=rpn_conv2d_3x3,
                                         num_outputs=256,
                                         kernel_size=[3, 3],
                                         stride=1,
                                         activation_fn=tf.nn.relu,
                                         weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
                                         biases_initializer=cfgs.SUBNETS_BIAS_INITIALIZER,
                                         scope='{}_{}'.format(scope_list[0], i),
                                         reuse=reuse_flag)
        add_heatmap(rpn_conv2d_3x3, name='cls_head_%s' % level)

        rpn_box_scores = slim.conv2d(rpn_conv2d_3x3,
                                     num_outputs=cfgs.CLASS_NUM * self.num_anchors_per_location,
                                     kernel_size=[3, 3],
                                     stride=1,
                                     weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
                                     biases_initializer=cfgs.FINAL_CONV_BIAS_INITIALIZER,
                                     scope=scope_list[2],
                                     activation_fn=None,
                                     reuse=reuse_flag)

        rpn_box_scores = tf.reshape(rpn_box_scores, [-1, cfgs.CLASS_NUM],
                                    name='rpn_{}_classification_reshape'.format(level))
        rpn_box_probs = tf.sigmoid(rpn_box_scores, name='rpn_{}_classification_sigmoid'.format(level))

        return rpn_box_scores, rpn_box_probs
Ejemplo n.º 2
0
    def rpn_reg_net(self, inputs, scope_list, reuse_flag, level):
        rpn_conv2d_3x3 = inputs
        for i in range(4):
            rpn_conv2d_3x3 = slim.conv2d(
                inputs=rpn_conv2d_3x3,
                num_outputs=256,
                kernel_size=[3, 3],
                weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
                biases_initializer=cfgs.SUBNETS_BIAS_INITIALIZER,
                stride=1,
                activation_fn=tf.nn.relu,
                scope='{}_{}'.format(scope_list[1], i),
                reuse=reuse_flag)
        add_heatmap(rpn_conv2d_3x3, name='reg_head_%s' % level)

        rpn_delta_boxes = slim.conv2d(
            rpn_conv2d_3x3,
            num_outputs=5 * self.num_anchors_per_location,
            kernel_size=[3, 3],
            stride=1,
            weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
            biases_initializer=cfgs.SUBNETS_BIAS_INITIALIZER,
            scope=scope_list[3],
            activation_fn=None,
            reuse=reuse_flag)

        rpn_head_cls = slim.conv2d(
            rpn_conv2d_3x3,
            num_outputs=4 * self.num_anchors_per_location,
            kernel_size=[3, 3],
            stride=1,
            weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
            biases_initializer=cfgs.SUBNETS_BIAS_INITIALIZER,
            scope=scope_list[4],
            activation_fn=None,
            reuse=reuse_flag)

        rpn_angle_cls = slim.conv2d(
            rpn_conv2d_3x3,
            num_outputs=self.angle_range * self.num_anchors_per_location,
            kernel_size=[3, 3],
            stride=1,
            weights_initializer=cfgs.SUBNETS_WEIGHTS_INITIALIZER,
            biases_initializer=cfgs.SUBNETS_BIAS_INITIALIZER,
            scope=scope_list[5],
            activation_fn=None,
            reuse=reuse_flag)

        rpn_delta_boxes = tf.reshape(
            rpn_delta_boxes, [-1, 5],
            name='rpn_{}_regression_reshape'.format(level))

        rpn_head_cls = tf.reshape(rpn_head_cls, [-1, 4],
                                  name='rpn_{}_head_cls_reshape'.format(level))

        rpn_angle_cls = tf.reshape(
            rpn_angle_cls, [-1, self.angle_range],
            name='rpn_{}_angle_cls_reshape'.format(level))

        return rpn_delta_boxes, rpn_head_cls, rpn_angle_cls
Ejemplo n.º 3
0
def resnet_base(img_batch, scope_name, is_training=True):
    if scope_name.endswith('b'):
        get_resnet_fn = get_resnet_v1_b_base
    elif scope_name.endswith('d'):
        get_resnet_fn = get_resnet_v1_d_base
    else:
        raise ValueError("scope Name erro....")

    _, feature_dict = get_resnet_fn(
        input_x=img_batch,
        scope=scope_name,
        bottleneck_nums=BottleNeck_NUM_DICT[scope_name],
        base_channels=BASE_CHANNELS_DICT[scope_name],
        is_training=is_training,
        freeze_norm=True,
        freeze=cfgs.FREEZE_BLOCKS)

    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, 2, -1):
        add_heatmap(pyramid_dict['P%d' % level],
                    name='Layer%d/P%d_heat' % (level, level))

    return pyramid_dict