9. /lib/rpn_msr/proposal_target_layer_tf.py
本文件实现了根据max_overlaps筛选前景和背景,并得到bbox regression targets等。
具体思路如下(右边页是思路,左边页是备注):
# --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick and Sean Bell
# --------------------------------------------------------
import yaml
import numpy as np
import numpy.random as npr
from fast_rcnn.config import cfg
from fast_rcnn.bbox_transform import bbox_transform
from utils.cython_bbox import bbox_overlaps
import pdb
DEBUG = False
#传入的数据为
# rpn_rois:blob,内容为[proposal引索(全零),proposal]
#gt_boxes:gtound-truth
#_num_classes:类别总数,21
#函数作用:
# 产生筛选后的roi,对应labels,三个(len(rois),4*21)大小的矩阵,其中一个对fg-roi对应引索行的对应类别的4个位置填上(dx,dy,dw,dh),另两个对fg-roi对应引索行的对应类别的4个位置填上(1,1,1,1)
def proposal_target_layer(rpn_rois, gt_boxes,_num_classes):
"""
Assign object detection proposals to ground-truth targets. Produces proposal
classification labels and bounding-box regression targets.
"""
# Proposal ROIs (0, x1, y1, x2, y2) coming from RPN
# (i.e., rpn.proposal_layer.ProposalLayer), or any other source
all_rois = rpn_rois
# TODO(rbg): it's annoying that sometimes I have extra info before
# and other times after box coordinates -- normalize to one format
# Include ground-truth boxes in the set of candidate rois
#建立一个(gt_boxes.shape[0]+proposals.shape[0],5)的array,proposals信息在上GT信息在下面,存入all_rois,GT引索全初始化为0
zeros = np.zeros((gt_boxes.shape[0], 1), dtype=gt_boxes.dtype)