Faster-RCNN筆記

Note

主要是之前在跑目標(biāo)檢測代碼時發(fā)現(xiàn)很多變量名都roixxx的,雖然之前看過相關(guān)的知識但是感覺又被繞暈了,同時發(fā)現(xiàn)了一片寫ROI Pooling之后反向傳播相關(guān)的知乎專欄于是做個筆記記錄下。同時為了日后更方便進行修改與調(diào)整加深印象。

FasterRCNN的結(jié)構(gòu)

faster-RCNN

輸入圖像的預(yù)處理

目標(biāo)檢測輸入圖像預(yù)處理的原因:

  1. 數(shù)據(jù)集圖片大小不一,需要將大小不一的圖片在一個batch內(nèi)組成統(tǒng)一的size
  2. 寬高比過于極端的圖片需要特定的裁剪方案
  3. 將不同大小的圖片縮放到同一尺度

處理過程如下圖所示


Preprocess

輸入圖像的縮放結(jié)果是將短邊尺度縮放到TargetSize,但如果這樣子縮放長邊超過了maxSize,那么縮放長邊,圖像的長寬比理論上是不變的。

圖像預(yù)處理代碼如下

def _get_image_blob(im):

  """Converts an image into a network input.
  Arguments:
  im (ndarray): a color image in BGR order
  Returns:
  blob (ndarray): a data blob holding an image pyramid
  im_scale_factors (list): list of image scales (relative to im) used
    in the image pyramid
  """
  im_orig = im.astype(np.float32, copy=True)
  im_orig -= cfg.PIXEL_MEANS

  im_shape = im_orig.shape
  im_size_min = np.min(im_shape[0:2])
  im_size_max = np.max(im_shape[0:2])

  processed_ims = []
  im_scale_factors = []

  for target_size in cfg.TEST.SCALES:
      im_scale = float(target_size) / float(im_size_min)
      # Prevent the biggest axis from being more than MAX_SIZE
      if np.round(im_scale * im_size_max) > cfg.TEST.MAX_SIZE:
          im_scale = float(cfg.TEST.MAX_SIZE) / float(im_size_max)
      im = cv2.resize(im_orig, None, None, fx=im_scale, fy=im_scale,
                      interpolation=cv2.INTER_LINEAR)
      im_scale_factors.append(im_scale)
      processed_ims.append(im)

  # Create a blob to hold the input images
  blob = im_list_to_blob(processed_ims)

  return blob, np.array(im_scale_factors)

cfg(配置文件)里的TEST.SCALES其實是TargetSize默認(rèn)為600,TEST.MAX_SIZE默認(rèn)為1000。
上述操作目前只解決了尺度相同的問題,但若要batch size > 1還需要其他處理

數(shù)據(jù)的載入

數(shù)據(jù)通過roibatchLoader載入dataset,然后將dataset裝入dataloader,此變換在minibatch.py內(nèi),實現(xiàn)后通過roibatchLoacer類內(nèi)調(diào)用

image->feature maps

一般情況下通過一系列卷積層(vgg16 or resnet)得到一個基準(zhǔn)特征圖(base feature map)上圖中黑黑的那塊。base feature map是512通道的。

forward

# feed image data to base model to obtain base feature map
base_feat = self.RCNN_base(im_data)

RPN網(wǎng)絡(luò)

RPN

參考

Object Detection and Classification using R-CNNs
一文讀懂Faster RCNN
faster-rcnn代碼閱讀理解(2)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容