1. 程式人生 > >faster rcnn generate_anchors 原始碼理解

faster rcnn generate_anchors 原始碼理解

這裡比較trick的就是_ratio_enum了,這裡是要生成面積一樣下,高寬比=0.5, 1, 2的所有矩形。

x是寬,x * x * 0.5 = area => x * x = area * 2

def _ratio_enum(anchor, ratios):
   """
   Enumerate a set of anchors for each aspect ratio wrt an anchor.
   """

   w, h, x_ctr, y_ctr = _whctrs(anchor)
   size = w * h
   size_ratios = size / ratios
   ws = np.round(np.sqrt(size_ratios))
   hs = np.round(ws * ratios)
   anchors = _mkanchors(ws, hs, x_ctr, y_ctr)
   return
anchors