def proposal_layer(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales): rpn_cls_prob_reshape = rpn_cls_prob_reshape.data.cpu().numpy() rpn_bbox_pred = rpn_bbox_pred.data.cpu().numpy() x = proposal_layer_py(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales) x = faster_rcnn.network.np_to_variable(x, is_cuda=True) return x.view(-1, 5)
def proposal_layer(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales): """ :param rpn_cls_prob_reshape: (1, 2*9_anchors, 37, 50) tensor :param rpn_bbox_pred: (1, 4*9_anchors, 37, 50) tensor :param im_info: (1, 3) numpy :param cfg_key: :param _feat_stride: :param anchor_scales: :return: """ rpn_cls_prob_reshape = rpn_cls_prob_reshape.data.cpu().numpy() rpn_bbox_pred = rpn_bbox_pred.data.cpu().numpy() x = proposal_layer_py(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales) x = network.np_to_variable(x, is_cuda=True) return x.view(-1, 5)
def __init__(self, debug=False): super(RPN, self).__init__() self.anchor_scales = cfg.ANCHOR_SCALES self.anchor_ratios = cfg.ANCHOR_RATIOS self.feat_stride = cfg.FEAT_STRIDE[0] self._vgg16 = VGG16() self.conv1 = Conv2d(512, 512, 3, same_padding=True) self.score_conv = Conv2d(512, len(self.anchor_scales) * len(self.anchor_ratios) * 2, 1, relu=False, same_padding=False) self.bbox_conv = Conv2d(512, len(self.anchor_scales) * len(self.anchor_ratios) * 4, 1, relu=False, same_padding=False) # define proposal layer self.proposal_layer = proposal_layer_py(self.feat_stride, self.anchor_scales, self.anchor_ratios) # define anchor target layer self.anchor_target_layer = anchor_target_layer_py( self.feat_stride, self.anchor_scales, self.anchor_ratios) # loss self.cross_entropy = 0 self.loss_box = 0 # for log self.debug = debug