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

Method forward

rfcn/operator_py/proposal.py:46–163  ·  view source on GitHub ↗
(self, is_train, req, in_data, out_data, aux)

Source from the content-addressed store, hash-verified

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