MCPcopy
hub / github.com/msracver/Deformable-ConvNets / forward

Method forward

faster_rcnn/operator_py/proposal.py:50–167  ·  view source on GitHub ↗
(self, is_train, req, in_data, out_data, aux)

Source from the content-addressed store, hash-verified

48 print self._anchors
49
50 def forward(self, is_train, req, in_data, out_data, aux):
51 nms = gpu_nms_wrapper(self._threshold, in_data[0].context.device_id)
52
53 batch_size = in_data[0].shape[0]
54 if batch_size > 1:
55 raise ValueError("Sorry, multiple images each device is not implemented")
56
57 # for each (H, W) location i
58 # generate A anchor boxes centered on cell i
59 # apply predicted bbox deltas at cell i to each of the A anchors
60 # clip predicted boxes to image
61 # remove predicted boxes with either height or width < threshold
62 # sort all (proposal, score) pairs by score from highest to lowest
63 # take top pre_nms_topN proposals before NMS
64 # apply NMS with threshold 0.7 to remaining proposals
65 # take after_nms_topN proposals after NMS
66 # return the top proposals (-> RoIs top, scores top)
67
68 pre_nms_topN = self._rpn_pre_nms_top_n
69 post_nms_topN = self._rpn_post_nms_top_n
70 min_size = self._rpn_min_size
71
72 # the first set of anchors are background probabilities
73 # keep the second part
74 scores = in_data[0].asnumpy()[:, self._num_anchors:, :, :]
75 bbox_deltas = in_data[1].asnumpy()
76 im_info = in_data[2].asnumpy()[0, :]
77
78 if DEBUG:
79 print 'im_size: ({}, {})'.format(im_info[0], im_info[1])
80 print 'scale: {}'.format(im_info[2])
81
82 # 1. Generate proposals from bbox_deltas and shifted anchors
83 # use real image size instead of padded feature map sizes
84 height, width = int(im_info[0] / self._feat_stride), int(im_info[1] / self._feat_stride)
85
86 if DEBUG:
87 print 'score map size: {}'.format(scores.shape)
88 print "resudial: {}".format((scores.shape[2] - height, scores.shape[3] - width))
89
90 # Enumerate all shifts
91 shift_x = np.arange(0, width) * self._feat_stride
92 shift_y = np.arange(0, height) * self._feat_stride
93 shift_x, shift_y = np.meshgrid(shift_x, shift_y)
94 shifts = np.vstack((shift_x.ravel(), shift_y.ravel(), shift_x.ravel(), shift_y.ravel())).transpose()
95
96 # Enumerate all shifted anchors:
97 #
98 # add A anchors (1, A, 4) to
99 # cell K shifts (K, 1, 4) to get
100 # shift anchors (K, A, 4)
101 # reshape to (K*A, 4) shifted anchors
102 A = self._num_anchors
103 K = shifts.shape[0]
104 anchors = self._anchors.reshape((1, A, 4)) + shifts.reshape((1, K, 4)).transpose((1, 0, 2))
105 anchors = anchors.reshape((K * A, 4))
106
107 # Transpose and reshape predicted bbox transformations to get them

Callers

nothing calls this directly

Calls 6

_clip_padMethod · 0.95
_filter_boxesMethod · 0.95
gpu_nms_wrapperFunction · 0.90
clip_boxesFunction · 0.90
nmsFunction · 0.90
reshapeMethod · 0.45

Tested by

no test coverage detected