def get_plane_anchors(self, anchor_scales: np.ndarray): """get anchors per location on feature map. The anchor number is anchor_scales x anchor_ratios """ base_anchor = Tensor([0, 0, self.base_size - 1, self.base_size - 1]) base_anchor = base_anchor.reshape(1, -1) w, h, x_ctr, y_ctr = self._whctrs(base_anchor) # ratio enumerate size = w * h size_ratios = size / self.anchor_ratios #pdb.set_trace() ws = F.sqrt(size_ratios) hs = ws * self.anchor_ratios # ws = size_ratios.sqrt().round() # hs = (ws * self.anchor_ratios).round() # scale enumerate anchor_scales = anchor_scales.reshape(1, -1).astype(np.float32) ws = F.expand_dims(ws, 1) hs = F.expand_dims(hs, 1) ws = (ws * anchor_scales).reshape(-1, 1) hs = (hs * anchor_scales).reshape(-1, 1) # make anchors anchors = F.concat( [ x_ctr - 0.5 * (ws - 1), y_ctr - 0.5 * (hs - 1), x_ctr + 0.5 * (ws - 1), y_ctr + 0.5 * (hs - 1), ], axis=1, ) return anchors.astype(np.float32)
def test_squeeze(): a = Tensor(1) a = a.reshape((1, 1)) assert F.squeeze(a).ndim == 0
def test_reshape(): a = Tensor(1) a = a.reshape((1, 1))
def test_max(): a = Tensor([1, 2]) a = a.reshape((1, 2)) assert a.max().ndim == 0 assert a.max(axis=1).ndim == 1