示例#1
0
    def build_fastrcnn(self, P_list, rois_list, img_shape):

        with tf.variable_scope('Fast-RCNN'):
            # 5. ROI Pooling
            with tf.variable_scope('rois_pooling'):
                pooled_features_list = []
                for level_name, p, rois in zip(cfgs.LEVLES, P_list,
                                               rois_list):  # exclude P6_rois
                    # p = tf.Print(p, [tf.shape(p)], summarize=10, message=level_name+'SHPAE***')
                    pooled_features = self.roi_pooling(feature_maps=p,
                                                       rois=rois,
                                                       img_shape=img_shape,
                                                       scope=level_name)
                    pooled_features_list.append(pooled_features)

                pooled_features = tf.concat(
                    pooled_features_list, axis=0)  # [minibatch_size, H, W, C]

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(
                    inputs=pooled_features,
                    is_training=self.is_training,
                    scope_name=self.base_network_name)
            elif self.base_network_name.startswith('Mobile'):
                fc_flatten = mobilenet_v2.mobilenetv2_head(
                    inputs=pooled_features, is_training=self.is_training)
            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            with slim.arg_scope([slim.fully_connected],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY)):

                cls_score = slim.fully_connected(
                    fc_flatten,
                    num_outputs=cfgs.CLASS_NUM + 1,
                    weights_initializer=cfgs.INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='cls_fc')

                bbox_pred = slim.fully_connected(
                    fc_flatten,
                    num_outputs=(cfgs.CLASS_NUM + 1) * 4,
                    activation_fn=None,
                    trainable=self.is_training,
                    weights_initializer=tf.random_normal_initializer(
                        mean=0.0, stddev=0.001),
                    scope='reg_fc')

                # for convient. It also produce (cls_num +1) bboxes
                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred = tf.reshape(bbox_pred,
                                       [-1, 4 * (cfgs.CLASS_NUM + 1)])

                return bbox_pred, cls_score
def build_fastrcnn(feature_to_cropped, rois, img_shape, base_network_name, is_training):
    with tf.variable_scope('Fast-RCNN'):
        # 1. ROI Pooling
        with tf.variable_scope('rois_pooling'):
            pooled_features = roi_pooling(feature_maps=feature_to_cropped, rois=rois, img_shape=img_shape)

        # 2. inferecne rois in Fast-RCNN to obtain fc_flatten features
        if base_network_name.startswith('resnet'):
            fc_flatten = resnet.restnet_head(input=pooled_features,
                                             is_training=is_training,
                                             scope_name=base_network_name)
        elif base_network_name.startswith('MobilenetV2'):
            fc_flatten = mobilenet_v2.mobilenetv2_head(inputs=pooled_features,
                                                       is_training=is_training)
        else:
            raise NotImplementedError('only support resnet and mobilenet')

        # 3. cls and reg in Fast-RCNN
        with tf.variable_scope('horizen_branch'):
            with slim.arg_scope([slim.fully_connected], weights_regularizer=slim.l2_regularizer(cfgs.WEIGHT_DECAY)):

                cls_score_h = slim.fully_connected(fc_flatten,
                                                   num_outputs=cfgs.CLASS_NUM + 1,
                                                   weights_initializer=cfgs.INITIALIZER,
                                                   activation_fn=None, trainable=is_training,
                                                   scope='cls_fc_h')

                bbox_pred_h = slim.fully_connected(fc_flatten,
                                                   num_outputs=(cfgs.CLASS_NUM + 1) * 4,
                                                   weights_initializer=cfgs.BBOX_INITIALIZER,
                                                   activation_fn=None, trainable=is_training,
                                                   scope='reg_fc_h')

                # for convient. It also produce (cls_num +1) bboxes

                cls_score_h = tf.reshape(cls_score_h, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred_h = tf.reshape(bbox_pred_h, [-1, 4 * (cfgs.CLASS_NUM + 1)])

        with tf.variable_scope('rotation_branch'):
            with slim.arg_scope([slim.fully_connected], weights_regularizer=slim.l2_regularizer(cfgs.WEIGHT_DECAY)):

                cls_score_r = slim.fully_connected(fc_flatten,
                                                   num_outputs=cfgs.CLASS_NUM + 1,
                                                   weights_initializer=cfgs.INITIALIZER,
                                                   activation_fn=None, trainable=is_training,
                                                   scope='cls_fc_r')

                bbox_pred_r = slim.fully_connected(fc_flatten,
                                                   num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                                                   weights_initializer=cfgs.BBOX_INITIALIZER,
                                                   activation_fn=None, trainable=is_training,
                                                   scope='reg_fc_r')
                # for convient. It also produce (cls_num +1) bboxes
                cls_score_r = tf.reshape(cls_score_r, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred_r = tf.reshape(bbox_pred_r, [-1, 5 * (cfgs.CLASS_NUM + 1)])

        return bbox_pred_h, cls_score_h, bbox_pred_r, cls_score_r
    def build_fastrcnn(self, feature_to_cropped, rois, img_shape):

        with tf.variable_scope('Fast-RCNN'):
            # 5. ROI Pooling
            with tf.variable_scope('rois_pooling'):

                rois = boxes_utils.get_horizen_minAreaRectangle(rois, False)

                pooled_features = self.roi_pooling(
                    feature_maps=feature_to_cropped,
                    rois=rois,
                    img_shape=img_shape)

                # xmin, ymin, xmax, ymax = tf.unstack(rois, axis=1)
                #
                # h = tf.maximum(ymax - ymin, 0)
                # w = tf.maximum(xmax - xmin, 0)
                # x_c = (xmax + xmin) // 2
                # y_c = (ymax + ymin) // 2
                # theta = tf.ones_like(h) * -90
                # rois = tf.transpose(tf.stack([x_c, y_c, h, w, theta]))

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(input=pooled_features,
                                                 is_training=self.is_training,
                                                 scope=self.base_network_name)
            elif self.base_network_name.startswith('MobilenetV2'):
                fc_flatten = mobilenet_v2.mobilenetv2_head(
                    inputs=pooled_features, is_training=self.is_training)
            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            with slim.arg_scope([slim.fully_connected],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY)):
                cls_score = slim.fully_connected(
                    fc_flatten,
                    num_outputs=cfgs.CLASS_NUM + 1,
                    weights_initializer=cfgs.INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='cls_fc')
                bbox_pred = slim.fully_connected(
                    fc_flatten,
                    num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                    weights_initializer=cfgs.BBOX_INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='reg_fc')
                # for convient. It also produce (cls_num +1) bboxes
                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred = tf.reshape(bbox_pred,
                                       [-1, 5 * (cfgs.CLASS_NUM + 1)])

            return bbox_pred, cls_score
    def build_fastrcnn(self, feature_to_cropped, rois, img_shape):

        with tf.variable_scope('Fast-RCNN'):
            # 5. ROI Pooling
            with tf.variable_scope('rois_pooling'):
                pooled_features = self.roi_pooling(feature_maps=feature_to_cropped, rois=rois, img_shape=img_shape)

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(input=pooled_features,
                                                 is_training=self.is_training,
                                                 scope_name=self.base_network_name)
            elif self.base_network_name.startswith('Mobile'):
                fc_flatten = mobilenet_v2.mobilenetv2_head(inputs=pooled_features,
                                                           is_training=self.is_training)
            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            # tf.variance_scaling_initializer()
            # tf.VarianceScaling()
            with slim.arg_scope([slim.fully_connected], weights_regularizer=slim.l2_regularizer(cfgs.WEIGHT_DECAY)):

                cls_score = slim.fully_connected(fc_flatten,
                                                 num_outputs=cfgs.CLASS_NUM+1,
                                                 weights_initializer=slim.variance_scaling_initializer(factor=1.0,
                                                                                                       mode='FAN_AVG',
                                                                                                       uniform=True),
                                                 activation_fn=None, trainable=self.is_training,
                                                 scope='cls_fc')

                bbox_pred = slim.fully_connected(fc_flatten,
                                                 num_outputs=(cfgs.CLASS_NUM+1)*4,
                                                 weights_initializer=slim.variance_scaling_initializer(factor=1.0,
                                                                                                       mode='FAN_AVG',
                                                                                                       uniform=True),
                                                 activation_fn=None, trainable=self.is_training,
                                                 scope='reg_fc')
                # for convient. It also produce (cls_num +1) bboxes

                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM+1])
                bbox_pred = tf.reshape(bbox_pred, [-1, 4*(cfgs.CLASS_NUM+1)])

        return bbox_pred, cls_score
示例#5
0
    def build_concat_fastrcnn(self, P_list, all_rois, img_shape):

        with tf.variable_scope('Fast-RCNN'):

            # 5.0 concat feature maps:

            h, w = tf.shape(P_list[0])[1], tf.shape(P_list[0])[2]

            concat_list = [P_list[0]]
            for l in range(1, len(
                    cfgs.LEVLES)):  # do not concat P6, do not upsample P2
                upsample_p = tf.image.resize_bilinear(P_list[l],
                                                      size=[h, w],
                                                      name='up_sample_%d' %
                                                      (l + 2))
                concat_list.append(upsample_p)
            concat_fet = tf.concat(concat_list, axis=-1)
            if cfgs.CONCAT_CHANNEL != 1024:
                print("concat channel is not 1024")
                concat_fet = slim.conv2d(concat_fet,
                                         activation_fn=None,
                                         num_outputs=cfgs.CONCAT_CHANNEL,
                                         kernel_size=[3, 3],
                                         padding="SAME",
                                         stride=1,
                                         scope="concat_fets",
                                         biases_initializer=None)

            # 5.1. ROI Pooling
            with tf.variable_scope('rois_pooling'):

                pooled_features = self.roi_pooling(concat_fet,
                                                   rois=all_rois,
                                                   img_shape=img_shape,
                                                   scope="all")

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(
                    inputs=pooled_features,
                    is_training=self.is_training,
                    scope_name=self.base_network_name)
            elif self.base_network_name.startswith('Mobile'):
                fc_flatten = mobilenet_v2.mobilenetv2_head(
                    inputs=pooled_features, is_training=self.is_training)
            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            with slim.arg_scope([slim.fully_connected],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY)):

                cls_score = slim.fully_connected(
                    fc_flatten,
                    num_outputs=cfgs.CLASS_NUM + 1,
                    weights_initializer=cfgs.INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='cls_fc')
                if cfgs.ADD_EXTR_CONVS_FOR_REG > 0:
                    bbox_input_feat = pooled_features
                    for i in range(cfgs.ADD_EXTR_CONVS_FOR_REG):
                        bbox_input_feat = slim.conv2d(bbox_input_feat,
                                                      num_outputs=256,
                                                      kernel_size=[3, 3],
                                                      stride=1,
                                                      padding="SAME",
                                                      scope='extra_conv%d' % i)
                    bbox_input_fc_feat = slim.flatten(
                        bbox_input_feat, scope='bbox_feat_flatten')

                    bbox_pred = slim.fully_connected(
                        bbox_input_fc_feat,
                        num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                        weights_initializer=cfgs.BBOX_INITIALIZER,
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='reg_fc')
                else:
                    bbox_pred = slim.fully_connected(
                        fc_flatten,
                        num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                        weights_initializer=cfgs.BBOX_INITIALIZER,
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='reg_fc')

                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred = tf.reshape(bbox_pred,
                                       [-1, 5 * (cfgs.CLASS_NUM + 1)])

                return bbox_pred, cls_score
示例#6
0
    def build_fastrcnn(self, P_list, rois_list, img_shape):

        with tf.variable_scope('Fast-RCNN'):
            # 5. ROI Pooling
            with tf.variable_scope('rois_pooling'):
                pooled_features_list = []
                for level_name, p, rois in zip(cfgs.LEVLES, P_list,
                                               rois_list):  # exclude P6_rois
                    # p = tf.Print(p, [tf.shape(p)], summarize=10, message=level_name+'SHPAE***')
                    pooled_features = self.roi_pooling(feature_maps=p,
                                                       rois=rois,
                                                       img_shape=img_shape,
                                                       scope=level_name)
                    pooled_features_list.append(pooled_features)

                pooled_features = tf.concat(
                    pooled_features_list, axis=0)  # [minibatch_size, H, W, C]

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(
                    inputs=pooled_features,
                    is_training=self.is_training,
                    scope_name=self.base_network_name)
            elif self.base_network_name.startswith('Mobile'):
                fc_flatten = mobilenet_v2.mobilenetv2_head(
                    inputs=pooled_features, is_training=self.is_training)
            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            with slim.arg_scope([slim.fully_connected],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY)):

                cls_score = slim.fully_connected(
                    fc_flatten,
                    num_outputs=cfgs.CLASS_NUM + 1,
                    weights_initializer=cfgs.INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='cls_fc')
                # if cfgs.ADD_EXTR_CONVS_FOR_REG > 0:
                #     bbox_input_feat = pooled_features
                #     for i in range(cfgs.ADD_EXTR_CONVS_FOR_REG):
                #         bbox_input_feat = slim.conv2d(bbox_input_feat, num_outputs=256, kernel_size=[3, 3], stride=1,
                #                                       padding="SAME", scope='extra_conv%d' % i)
                #     bbox_input_fc_feat = slim.flatten(bbox_input_feat, scope='bbox_feat_flatten')
                #
                #     bbox_pred = slim.fully_connected(bbox_input_fc_feat,
                #                                      num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                #                                      weights_initializer=cfgs.BBOX_INITIALIZER,
                #                                      activation_fn=None, trainable=self.is_training,
                #                                      scope='reg_fc')
                # else:
                #     bbox_pred = slim.fully_connected(fc_flatten,
                #                                      num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                #                                      weights_initializer=cfgs.BBOX_INITIALIZER,
                #                                      activation_fn=None, trainable=self.is_training,
                #                                      scope='reg_fc')

                bbox_input_feat = pooled_features
                for i in range(cfgs.ADD_EXTR_CONVS_FOR_REG):
                    bbox_input_feat = slim.conv2d(bbox_input_feat,
                                                  num_outputs=256,
                                                  kernel_size=[3, 3],
                                                  stride=1,
                                                  padding="SAME",
                                                  scope='extra_conv%d' % i)
                bbox_input_fc_feat = slim.flatten(bbox_input_feat,
                                                  scope='bbox_feat_flatten')

                bbox_pred = slim.fully_connected(
                    bbox_input_fc_feat,
                    num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                    weights_initializer=cfgs.BBOX_INITIALIZER,
                    activation_fn=None,
                    trainable=self.is_training,
                    scope='reg_fc')

                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred = tf.reshape(bbox_pred,
                                       [-1, 4 * (cfgs.CLASS_NUM + 1)])

                cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                bbox_pred = tf.reshape(bbox_pred,
                                       [-1, 5 * (cfgs.CLASS_NUM + 1)])

                return bbox_pred, cls_score
示例#7
0
    def build_fastrcnn(self, feature_to_cropped, rois, img_shape, scope):

        with tf.variable_scope('Fast-RCNN_{}'.format(scope)):
            # 5. ROI Pooling
            with tf.variable_scope('rois_pooling'):
                pooled_features = self.roi_pooling(
                    feature_maps=feature_to_cropped,
                    rois=rois,
                    img_shape=img_shape)

            # 6. inferecne rois in Fast-RCNN to obtain fc_flatten features
            if self.base_network_name.startswith('resnet'):
                fc_flatten = resnet.restnet_head(
                    input=pooled_features,
                    is_training=self.is_training,
                    scope_name=self.base_network_name,
                    stage=scope)

            else:
                raise NotImplementedError('only support resnet and mobilenet')

            # 7. cls and reg in Fast-RCNN
            # tf.variance_scaling_initializer()
            # tf.VarianceScaling()
            with slim.arg_scope([slim.fully_connected],
                                weights_regularizer=slim.l2_regularizer(
                                    cfgs.WEIGHT_DECAY)):
                if not scope == 'stage3':

                    cls_score = slim.fully_connected(
                        fc_flatten,
                        num_outputs=cfgs.CLASS_NUM + 1,
                        weights_initializer=slim.variance_scaling_initializer(
                            factor=1.0, mode='FAN_AVG', uniform=True),
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='cls_fc_h')

                    bbox_pred = slim.fully_connected(
                        fc_flatten,
                        num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                        weights_initializer=slim.variance_scaling_initializer(
                            factor=1.0, mode='FAN_AVG', uniform=True),
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='reg_fc_h')

                    # for convient. It also produce (cls_num +1) bboxes
                    cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                    bbox_pred = tf.reshape(bbox_pred,
                                           [-1, 5 * (cfgs.CLASS_NUM + 1)])
                    bbox_pred_ins = tf.reshape(bbox_pred,
                                               [-1, cfgs.CLASS_NUM + 1, 5])

                    # only keep a box which score is the bigest
                    keep_abox = tf.argmax(cls_score, axis=1)
                    keep_inds = tf.reshape(
                        tf.transpose(
                            tf.stack([
                                tf.cumsum(tf.ones_like(keep_abox)) - 1,
                                keep_abox
                            ])), [-1, 2])
                    bbox_pred_fliter = tf.reshape(
                        tf.gather_nd(bbox_pred_ins, keep_inds), [-1, 5])

                    return bbox_pred_fliter, bbox_pred, cls_score
                else:
                    cls_score = slim.fully_connected(
                        fc_flatten,
                        num_outputs=cfgs.CLASS_NUM + 1,
                        weights_initializer=slim.variance_scaling_initializer(
                            factor=1.0, mode='FAN_AVG', uniform=True),
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='cls_fc_r')

                    bbox_pred = slim.fully_connected(
                        fc_flatten,
                        num_outputs=(cfgs.CLASS_NUM + 1) * 5,
                        weights_initializer=slim.variance_scaling_initializer(
                            factor=1.0, mode='FAN_AVG', uniform=True),
                        activation_fn=None,
                        trainable=self.is_training,
                        scope='reg_fc_r')
                    cls_score = tf.reshape(cls_score, [-1, cfgs.CLASS_NUM + 1])
                    bbox_pred = tf.reshape(bbox_pred,
                                           [-1, 5 * (cfgs.CLASS_NUM + 1)])
                    return bbox_pred, cls_score
示例#8
0
    def build_whole_detection_network(self, input_img_batch, gtboxes_batch):

        if self.is_training:
            # ensure shape is [M, 5]
            gtboxes_batch = tf.reshape(gtboxes_batch, [-1, 5])
            gtboxes_batch = tf.cast(gtboxes_batch, tf.float32)

        img_shape = tf.shape(input_img_batch)

        # 1.0 build base network
        rpn_base = self.build_base_network(input_img_batch)

        # 1.1 build the head_base network
        if self.base_network_name.startswith('resnet_v1'):
            rfcn_base = resnet.restnet_head(rpn_base,
                                            scope_name=self.base_network_name,
                                            is_training=self.is_training)

        elif self.base_network_name.startswith('MobilenetV2'):
            rfcn_base = mobilenet_v2.mobilenetv2_head(
                rpn_base, is_training=self.is_training)

        else:
            raise ValueError('Sorry, we only support resnet or mobilenet_v2')

        # 2. build rpn head
        with tf.variable_scope('build_rpn',
                               regularizer=slim.l2_regularizer(
                                   cfgs.WEIGHT_DECAY)):

            rpn_conv3x3 = slim.conv2d(rpn_base,
                                      128, [3, 3],
                                      trainable=self.is_training,
                                      weights_initializer=cfgs.INITIALIZER,
                                      activation_fn=tf.nn.relu,
                                      scope='rpn_conv/3x3')
            rpn_cls_score = slim.conv2d(rpn_conv3x3,
                                        self.num_anchors_per_location * 2,
                                        [1, 1],
                                        stride=1,
                                        trainable=self.is_training,
                                        weights_initializer=cfgs.INITIALIZER,
                                        activation_fn=None,
                                        scope='rpn_cls_score')
            rpn_box_pred = slim.conv2d(
                rpn_conv3x3,
                self.num_anchors_per_location * 4, [1, 1],
                stride=1,
                trainable=self.is_training,
                weights_initializer=cfgs.BBOX_INITIALIZER,
                activation_fn=None,
                scope='rpn_bbox_pred')
            rpn_box_pred = tf.reshape(rpn_box_pred, [-1, 4])
            rpn_cls_score = tf.reshape(rpn_cls_score, [-1, 2])
            rpn_cls_prob = slim.softmax(rpn_cls_score, scope='rpn_cls_prob')

        # 3. generate_anchors
        featuremap_height, featuremap_width = tf.shape(rpn_base)[1], tf.shape(
            rpn_base)[2]
        featuremap_height = tf.cast(featuremap_height, tf.float32)
        featuremap_width = tf.cast(featuremap_width, tf.float32)

        anchors = anchor_utils.make_anchors(
            base_anchor_size=cfgs.BASE_ANCHOR_SIZE_LIST[0],
            anchor_scales=cfgs.ANCHOR_SCALES,
            anchor_ratios=cfgs.ANCHOR_RATIOS,
            featuremap_height=featuremap_height,
            featuremap_width=featuremap_width,
            stride=cfgs.ANCHOR_STRIDE,
            name="make_anchors_forRPN")

        # 4. postprocess rpn proposals. such as: decode, clip, NMS
        with tf.variable_scope('postprocess_RPN'):
            rois, roi_scores = postprocess_rpn_proposals(
                rpn_bbox_pred=rpn_box_pred,
                rpn_cls_prob=rpn_cls_prob,
                img_shape=img_shape,
                anchors=anchors,
                is_training=self.is_training)
            # rois shape [-1, 4]
            # +++++++++++++++++++++++++++++++++++++add img smry+++++++++++++++++++++++++++++++++++++++++++++++++++++++

            if self.is_training:
                rois_in_img = show_box_in_tensor.draw_boxes_with_scores(
                    img_batch=input_img_batch, boxes=rois, scores=roi_scores)
                tf.summary.image('all_rpn_rois', rois_in_img)

                score_gre_05 = tf.reshape(
                    tf.where(tf.greater_equal(roi_scores, 0.5)), [-1])
                score_gre_05_rois = tf.gather(rois, score_gre_05)
                score_gre_05_score = tf.gather(roi_scores, score_gre_05)
                score_gre_05_in_img = show_box_in_tensor.draw_boxes_with_scores(
                    img_batch=input_img_batch,
                    boxes=score_gre_05_rois,
                    scores=score_gre_05_score)
                tf.summary.image('score_greater_05_rois', score_gre_05_in_img)
            # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        if self.is_training:
            with tf.variable_scope('sample_anchors_minibatch'):
                rpn_labels, rpn_bbox_targets = \
                    tf.py_func(
                        anchor_target_layer,
                        [gtboxes_batch, img_shape, anchors],
                        [tf.float32, tf.float32])
                rpn_bbox_targets = tf.reshape(rpn_bbox_targets, [-1, 4])
                rpn_labels = tf.to_int32(rpn_labels, name="to_int32")
                rpn_labels = tf.reshape(rpn_labels, [-1])
                self.add_anchor_img_smry(input_img_batch, anchors, rpn_labels)

            # --------------------------------------add smry----------------------------------------------------------

            rpn_cls_category = tf.argmax(rpn_cls_prob, axis=1)
            kept_rpppn = tf.reshape(tf.where(tf.not_equal(rpn_labels, -1)),
                                    [-1])
            rpn_cls_category = tf.gather(rpn_cls_category, kept_rpppn)
            acc = tf.reduce_mean(
                tf.to_float(
                    tf.equal(rpn_cls_category,
                             tf.to_int64(tf.gather(rpn_labels, kept_rpppn)))))
            tf.summary.scalar('ACC/rpn_accuracy', acc)

            with tf.control_dependencies([rpn_labels]):
                with tf.variable_scope('sample_RFCN_minibatch'):
                    rois, labels, bbox_targets = \
                    tf.py_func(proposal_target_layer,
                               [rois, gtboxes_batch],
                               [tf.float32, tf.float32, tf.float32])
                    rois = tf.reshape(rois, [-1, 4])
                    labels = tf.to_int32(labels)
                    labels = tf.reshape(labels, [-1])
                    bbox_targets = tf.reshape(bbox_targets,
                                              [-1, 4 * (cfgs.CLASS_NUM + 1)])
                    self.add_roi_batch_img_smry(input_img_batch, rois, labels)

        # -------------------------------------------------------------------------------------------------------------#
        #                                                          RFCN                                                #
        # -------------------------------------------------------------------------------------------------------------#
        # 5. build rfcn head
        bbox_pred, cls_score = self.build_rfcn_head(
            rfcn_base=rfcn_base,
            rois=rois,
            img_shape=img_shape,
            bin_nums=[3, 3],
            crop_size=[9, 9])  # crop_size is the total size
        # bbox_pred shape: [-1, 4*(cls_num+1)].
        # cls_score shape: [-1, cls_num+1]

        cls_prob = slim.softmax(cls_score, 'cls_prob')

        # ----------------------------------------------add smry-------------------------------------------------------
        if self.is_training:
            cls_category = tf.argmax(cls_prob, axis=1)
            rfcn_acc = tf.reduce_mean(
                tf.to_float(tf.equal(cls_category, tf.to_int64(labels))))
            tf.summary.scalar('ACC/rfcn_acc', rfcn_acc)

        #  6. postprocess_rfcn
        if not self.is_training:
            return self.postprocess_rfcn(rois=rois,
                                         bbox_ppred=bbox_pred,
                                         scores=cls_prob,
                                         img_shape=img_shape)
        else:
            '''
            when trian. We need build Loss
            '''
            loss_dict = self.build_loss(rpn_box_pred=rpn_box_pred,
                                        rpn_bbox_targets=rpn_bbox_targets,
                                        rpn_cls_score=rpn_cls_score,
                                        rpn_labels=rpn_labels,
                                        bbox_pred=bbox_pred,
                                        bbox_targets=bbox_targets,
                                        cls_score=cls_score,
                                        labels=labels)

            final_bbox, final_scores, final_category = self.postprocess_rfcn(
                rois=rois,
                bbox_ppred=bbox_pred,
                scores=cls_prob,
                img_shape=img_shape)
            return final_bbox, final_scores, final_category, loss_dict