def test_multiclass_nms(self): program = Program() with program_guard(program): bboxes = layers.data( name='bboxes', shape=[-1, 10, 4], dtype='float32') scores = layers.data(name='scores', shape=[-1, 10], dtype='float32') output = layers.multiclass_nms(bboxes, scores, 0.3, 400, 200, 0.7) self.assertIsNotNone(output)
def proposal_for_single_sample(self, anchors, bbox_deltas, im_info, scores, variances): proposal_num = paddle.shape(scores)[0] pre_nms_top_n_tensor = paddle.assign( np.asarray([self.pre_nms_topN], dtype='int32')) k_candidate = paddle.concat([proposal_num, pre_nms_top_n_tensor]) k = paddle.min(k_candidate) scores, index = paddle.topk(scores, k=k, axis=0) bbox_deltas = paddle.gather(bbox_deltas, index, axis=0) anchors = paddle.gather(anchors, index, axis=0) variances = paddle.gather(variances, index, axis=0) proposal = self.box_encode(anchors, bbox_deltas, variances) im_h, im_w, im_s = paddle.tensor.split(im_info, axis=1, num_or_sections=3) proposal = self.clip_tiled_boxes(im_w, im_h, proposal) keep = self.filter_boxes(proposal, im_w, im_h, im_s, self.min_size) tail_proposal = paddle.zeros(shape=[1, 4], dtype=proposal.dtype) proposal_num = paddle.shape(proposal)[0] tail_keep = paddle.reshape(proposal_num, shape=[1, 1]) tail_keep = paddle.cast(tail_keep, dtype=keep.dtype) tail_scores = paddle.zeros(shape=[1, 1], dtype=scores.dtype) proposal = paddle.concat([proposal, tail_proposal]) keep = paddle.concat([keep, tail_keep]) scores = paddle.concat([scores, tail_scores]) bbox_sel = paddle.gather(proposal, keep, axis=0) scores_sel = paddle.gather(scores, keep, axis=0) proposal = paddle.unsqueeze(bbox_sel, axis=0) scores = paddle.transpose(scores_sel, perm=[1, 0]) scores = paddle.unsqueeze(scores, axis=0) out = layers.multiclass_nms(proposal, scores, background_label=-1, nms_top_k=self.pre_nms_topN, score_threshold=-1., keep_top_k=self.post_nms_topN, nms_threshold=self.nms_thresh, normalized=False, nms_eta=self.eta) label, scores, proposal = paddle.tensor.split( out, axis=1, num_or_sections=[1, 1, 4]) return scores, proposal