def _retina_detach(self, out): ''' ##### Author [email protected] Solving bounding boxes. Parameters ---------- out: map object of staggered scores and deltas. scores, deltas = next(out), next(out) Each scores has shape [N, A*4, H, W]. Each deltas has shape [N, A*4, H, W]. N is the batch size. A is the shape[0] of base anchors declared in the fpn dict. H, W is the heights and widths of the anchors grid, based on the stride and input image's height and width. Returns ------- Generator of list, each list has [boxes, scores]. Usage ----- >>> np.block(list(self._retina_solving(out))) ''' buffer, anchors = out[0].asnumpy(), out[1] mask = buffer[:, 4] > self.threshold deltas = buffer[mask] nonlinear_pred(anchors[mask], deltas) deltas[:, :4] /= self.scale return deltas
def deal_with_fpn(fpn, scores, deltas): anchors = self._anchors_plane(*deltas.shape[-2:], *fpn).reshape( (-1, 4)) scores = scores[:, fpn[1].shape[0]:, :, :].transpose( (0, 2, 3, 1)).reshape((-1, 1)) deltas = deltas.transpose((0, 2, 3, 1)).reshape((-1, 4)) mask = scores.reshape((-1, )) > self.threshold proposals = deltas[mask] nonlinear_pred(anchors[mask], proposals) return [proposals / scale, scores[mask]]
def _retina_solving(self, out): ''' ##### Author [email protected] Solving bounding boxes. Parameters ---------- out: map object of staggered scores and deltas. scores, deltas = next(out), next(out) Each scores has shape [N, A*4, H, W]. Each deltas has shape [N, A*4, H, W]. N is the batch size. A is the shape[0] of base anchors declared in the fpn dict. H, W is the heights and widths of the anchors grid, based on the stride and input image's height and width. Returns ------- Generator of list, each list has [boxes, scores]. Usage ----- >>> np.block(list(self._retina_solving(out))) ''' for fpn in self._fpn_anchors: scores, deltas = next(out)[:, fpn[1].shape[0]:, ...], next(out) scores = scores.transpose((0, 2, 3, 1)).reshape((-1, 1)) mask = scores.ravel() > self.threshold anchors = self._get_runtime_anchors(*deltas.shape[-2:], *fpn)[mask] deltas = deltas.transpose((0, 2, 3, 1)).reshape((-1, 4))[mask] nonlinear_pred(anchors, deltas) yield [deltas / self.scale, scores[mask]]