1. 程式人生 > >Tensorflow object detection API 原始碼閱讀筆記:RFCN

Tensorflow object detection API 原始碼閱讀筆記:RFCN

有了前面Faster R-CNN的基礎,RFCN就比較容易了。

"""object_detection/meta_architectures/rfcn_meta_arch.py
The R-FCN meta architecture is similar to Faster R-CNN and only differs in the
second stage. Hence this class inherits FasterRCNNMetaArch and overrides only
the `_predict_second_stage` method
"""

改動比較大的地方如下:
    box_predictions = self._rfcn_box_predictor.predict(
        box_classifier_features,
        num_predictions_per_location=1
, scope=self.second_stage_box_predictor_scope, proposal_boxes=proposal_boxes_normalized) 只改動了這麼一點的原因是程式碼實現和原始paper不是完全一致的,見作者的paper:3.4. Training and hyperparameter tuning。 另外注意,在faster r-cnn中,是先經過ROI poooling,然後進入第二階段特徵提取器。而在rfcn中,是先進行第二階段特徵提取,然後進入RfcnBoxPredictor。這正是frcn改進的地方,即將卷積操作儘量在faster r-cnn的roi之間共享,使得rfcn得到的(更高層面的)roi需要單獨經過的預測層更少,大大提高了效率。
"""先回顧一下faster rcnn: ROI pooling"""
實現程式碼在
  def _compute_second_stage_input_feature_maps(self, features_to_crop,
                                               proposal_boxes_normalized)
ROI就是features_to_crop(第一階段特徵提取器得到的feature map)上的一塊crop,是依據proposal_boxed擷取的。ROI pooling是spp layer的特殊情況,就是通過自適應大小的卷積將特徵圖對映到固定尺寸,以便進入fc層。tf程式碼作者採用的實現不是這種,而是將不同尺寸的ROI先變成統一的大小,然後就不需要進行ROI pooling了(見_compute_second_stage_input_feature_maps),換言之,需要ROI POOLING的原因就是ROI的尺寸是不同的(RFCN PAPER的理解角度:this
region-specific operation breaks down translation invariance, and the post-RoI convolutional layers are no longer translation-invariant when evaluated across different regions.)。

這裡寫圖片描述

這裡寫圖片描述

"""rfcn的基本想法上面分析對比過了,仔細看看rfcn paper中的三張大圖就懂什麼是position-sensitive了。為什麼需要用position-sensitive RoI pooling呢?paper中說是為了將translation variance包含進FCN中。但是從position-sensitive score maps的生成來看,似乎類似顯示地引入了一種“先驗結構”,如上圖的fig 3,怎麼就能確保這九個score map剛好就是對應九個位置呢(For example, the “top-center-sensitive” score map exhibits high scores roughly near the top-center position of an object.)?
position-sensitive score maps
position-sensitive RoI pooling layer
"""

在Tensorflow object detection API中的實現有所不同:
class RfcnBoxPredictor(BoxPredictor)
Applies a position sensitve ROI pooling on position sensitive feature maps to
  predict classes and refined locations

ops.position_sensitive_crop_regions
  """Position-sensitive crop and pool rectangular regions from a feature grid.
  The output crops are split into `spatial_bins_y` vertical bins
  and `spatial_bins_x` horizontal bins. For each intersection of a vertical
  and a horizontal bin the output values are gathered by performing
  `tf.image.crop_and_resize` (bilinear resampling) on a a separate subset of
  channels of the image. This reduces `depth` by a factor of
  `(spatial_bins_y * spatial_bins_x)`.
  When global_pool is True, this function implements a differentiable version
  of position-sensitive RoI pooling used in
  [R-FCN detection system](https://arxiv.org/abs/1605.06409).
  When global_pool is False, this function implements a differentiable version
  of position-sensitive assembling operation used in
  [instance FCN](https://arxiv.org/abs/1603.08678)."""

'''
目測是將第二階段提取器得到的feature用1*1卷積增加到k*k*(c+1)個channel,就得到了position-sensitive score maps:
      location_feature_map_depth = (self._num_spatial_bins[0] *
                                    self._num_spatial_bins[1] *
                                    self.num_classes *
                                    self._box_code_size)
      location_feature_map = slim.conv2d(net, location_feature_map_depth,
                                         [1, 1], activation_fn=None,
                                         scope='refined_locations')
然後就用了和faster rcnn程式碼類似的方法,進行position-sensitive RoI pooling。position-sensitive score maps這個地方確實類似一種“先驗結構”。經常在paper中看到這種想法大膽的end-to-end先驗結構。論文中說With end-to-end training, this RoI layer shepherds the last convolutional layer to learn specialized position-sensitive score maps,視覺化的結果似乎確實有這種現象,有趣。
'''

相關推薦

Tensorflow object detection API 原始碼閱讀筆記RFCN

有了前面Faster R-CNN的基礎,RFCN就比較容易了。 """object_detection/meta_architectures/rfcn_meta_arch.py The R-FCN

Tensorflow object detection API 原始碼閱讀筆記RPN

Update: 建議先看從程式設計實現角度學習Faster R-CNN,比較直觀。這裡由於原始碼抽象程度較高,顯得比較混亂。 faster_rcnn_meta_arch.py中這兩個對應知乎文章中RPN包含的3*3和1*1卷積: rpn_box_pred

Tensorflow object detection API 原始碼閱讀筆記架構

在之前的博文中介紹過用tf提供的預訓練模型進行inference,非常簡單。這裡我們深入原始碼,瞭解檢測API的程式碼架構,每個部分的深入閱讀留待後續。 '''構建自己模型的介面是虛基類DetectionModel,具體有5個抽象函式需要實現。 ''' o

初窺Tensorflow Object Detection API 原始碼之(1) FeatureExtractor

models/research/object_detection/models/faster_rcnn_resnet_v1_feature_extractor.py models/research/object_detection/meta_a

谷歌開源Tensorflow Object Detection API學習筆記

谷歌宣佈開源其內部使用的 TensorFlow Object Detection API 物體識別系統。本教程針對ubuntu16.04系統,快速搭建環境以及實現視訊物體識別系統功能。 https://yq.aliyun.com/ziliao/405237 https://www.cnblo

配置tensorflow object detection api

could ror blog test creat not pre setup.py python 3:安裝tensorflow model 以及slim 版本號為1.4以上的,model和slim均在research 文件夾下 打開research文件目錄 python

谷歌開源的TensorFlow Object Detection API視頻物體識別系統實現教程

cti blog tail xiaoxiao pan clas post ont 谷歌 教程:http://blog.csdn.net/xiaoxiao123jun/article/details/76605928 全部代碼:https://github.com/lyj83

#tensorflow object detection api 源碼分析

clas fas mask api 錯誤 眼界 沒有 lan 入門深度學習 前言 Tensorflow 推出的 Object Detection API是一套抽象程度極高的目標檢測框架,可以快速用於生產部署。但網絡上大多數相關的中英文文章均只局限於應用層面的分析,對於該套

TensorFlow object detection API

storage 系統 pipeline -s doc 直接下載 and 獲取數據 ons https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_pet

TensorFlow object detection API應用一

ofo ash png figure lin 調用 安裝包 pat eight 目標檢測在圖形識別的基礎上有了更進一步的應用,但是代碼也更加繁瑣,TensorFlow專門為此開設了一個object detection API,接下來看看怎麽使用它。 一、object det

Ubuntu 16.04 安裝Tensorflow Object Detection API遇到的問題解決

** Ubuntu 16.04 安裝Tensorflow Object Detection API ** 本篇的內容主要參考以下連結:https://blog.csdn.net/pkokocl/article/details/82596089, 該博主描述的比較清楚,對於解決實際

Tensorflow Object Detection API之MaskRCNN-資料處理篇

TensorFlow官網介紹:Run an Instance Segmentation Model 要求將資料處理為PNG Instance Segmentation Masks格式 以下部分為處理單張Mask圖片的方式: from PIL import Image, ImageDr

Tensorflow object detection API--修改visualization_utils檔案,裁剪並儲存bounding box部分

任務描述:用Tensorflow object detection API檢測出來的結果是一整張圖片,想要把檢測出的bounding box部分單獨截取出來並儲存 執行環境:spyder 效果展示: 測試圖片:test_images --> 檢測圖片:testsave_images -

基於TensorFlow Object Detection API進行相關開發的步驟

1/安裝或升級protoc 2/編譯proto檔案 protoc object_detection/protos/*.proto --python_out=. 3將slim加入PYTHONPATH export PYTHONPATH="$PYTHONPATH:/home/user/DL

Tensorflow Object Detection API安裝與使用

一、簡介 《21個專案玩轉深度學習:基於Tensorflow的實踐詳解》第五章實踐 win10、jupyter notebook、python3.6, Tensorflow Object Detection API專案地址:https://github.com/tensorflow/mo

Tensorflow object detection API(1)---環境搭建與測試

    參考: https://blog.csdn.net/dy_guox/article/details/79081499 https://blog.csdn.net/u010103202/article/details/79899293 https://blog.csdn.n

windows+tensorflow object detection api 深度學習目標檢測實踐

1、在github上下載tensorflow/model專案 1. 首先把protoc-win32資料夾下面的protoc.exe移至protobuf-python/src目錄下。 2. 在cmd中進入protobuf-python/python目錄,先執行a

TensorFlow Object Detection API 超詳細教程和踩坑過程(安裝)

目錄     cuda安裝     cudnn安裝     anaconda安裝並建立環境     tensorflow環境     Tensorflow.models下載     Protobuf配置與測試 1.配置環境       首先說一下我

TensorFlow Object Detection API 超詳細教程和踩坑過程(資料準備和訓練)

1.準備資料     object detection的資料是需要tfrecord格式的,但是一般我們還是先製作voc格式的資料更加方便。     1.voc格式資料的準備:github上下載一個label-img:    然後選擇VOC格式,開始漫長的資料

基於谷歌開源的TensorFlow Object Detection API視訊物體識別系統實現教程

安裝Python 進入Python3.6.2下載頁,選擇 Files 中Windows平臺的Python安裝包,下載並安裝(本人安裝的是3.6.2版本的python,可根據實際情況下載不同版本的python) 安裝TensorFlow 進入TensorFlow