『計算機視覺』Mask-RCNN_項目文檔翻譯


基礎介紹

項目地址Mask_RCNN

語言框架:Python 3, Keras, and TensorFlow

Python 3.4, TensorFlow 1.3, Keras 2.0.8 其他依賴見:requirements.txt

基礎網絡:Feature Pyramid Network (FPN) and a ResNet101 backbone

文件介紹

以下是模型主體文件,

demo.ipynb Is the easiest way to start. It shows an example of using a model pre-trained on MS COCO to segment objects in your own images. It includes code to run object detection and instance segmentation on arbitrary images.

train_shapes.ipynb shows how to train Mask R-CNN on your own dataset. This notebook introduces a toy dataset (Shapes) to demonstrate training on a new dataset.

(model.py, utils.py, config.py): These files contain the main Mask RCNN implementation.

下面的幾個文件是觀察理解模型所用,

inspect_data.ipynb. This notebook visualizes the different pre-processing steps to prepare the training data.

inspect_model.ipynb This notebook goes in depth into the steps performed to detect and segment objects. It provides visualizations of every step of the pipeline.

inspect_weights.ipynb This notebooks inspects the weights of a trained model and looks for anomalies and odd patterns.

 可視化展示

下面圖片展示了RPN網絡的輸出,即同時包含了積極錨框和消極錨框的proposal們:

下面展示了送入回歸器之前的(第一步中的proposal)和最終輸出的定位框坐標:

mask展示,

查看不同層的激活特征,

權重分布直方圖,

調用訓練

Training on MS COCO

作者已經提供了一個預訓練好的基於COCO數據的權重以便我們快速啟動訓練任務,相關代碼位於samples/coco/coco.py我們既可以將之作為包導入到自己的代碼中,也可以如下在命令行直接調用該部分代碼,

# Train a new model starting from pre-trained COCO weights
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=coco

# Train a new model starting from ImageNet weights
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=imagenet

# Continue training a model that you had trained earlier
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=/path/to/weights.h5

# Continue training the last model you trained. This will find
# the last trained weights in the model directory.
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=last

 如果我們希望驗證COCO數據於最后保存的模型之上,

# Run COCO evaluation on the last trained model
python3 samples/coco/coco.py evaluate --dataset=/path/to/coco/ --model=last

相關參數仍然位於samples/coco/coco.py

Training on Your Own Dataset

 作者推薦了一篇博客blog post about the balloon color splash sample,介紹了從標注圖片到訓練它們再到將結果應用於一個小例子中的流程,其源碼也位於本項目內,見samples/coco/balloon

 為了訓練自己的數據,我們需要修改繼承兩個類,

Config This class contains the default configuration.

    Subclass it and modify the attributes you need to change.

Dataset This class provides a consistent way to work with any dataset.   // 一個class可以處理不同數據集

      It allows you to use new datasets for training without having to change the code of the model.   // 通過這個class我們可以最大程度避免修改model文件本身

      It also supports loading multiple datasets at the same time, which is useful if the objects you want to detect are not all available in one dataset.   // 可以同時處理不同數據集用於一次訓練,滿足特殊需求

有關使用示例見這四個文件:

samples/shapes/train_shapes.ipynb

samples/coco/coco.py

samples/balloon/balloon.py

samples/nucleus/nucleus.py

不同於論文之處

為了代碼的簡單和可擴展性,作者對工程進行了小幅度調整,其統計如下:

Image Resizing:本工程的圖像尺寸預調整不同於原論文中的,以COCO數據集為例,作者將數據調整為1024*1024的大小,為了保證長寬比不變(語義不受影響),作者采取了填充0將圖片變為1:1長寬比的方式,而非直接裁剪插值。

Bounding Boxes:數據集中的數據標簽,除了帶有mask標簽之外,還有gt box標簽,作者為了統一並簡化操作,舍棄了box標簽,完全使用mask圖,使用它們生成一個完全覆蓋全部標記像素的框作為gt box,這一步驟很大程度上簡化了圖像增強操作,很多例如旋轉處理一樣的預處理操一旦涉及gt box就會變得很麻煩,采用mash生成方式可以使得預處理操作更為方便。

為了驗證計算出來的gt box和原數據gt box的差異,作者進行了比較,效果如下:

We found that ~2% of bounding boxes differed by 1px or more, ~0.05% differed by 5px or more, and only 0.01% differed by 10px or more.

Learning Rate:原論文使用0.02的學習率,作者實驗覺得該學習率偏大,經常性造成梯度爆炸,特別是當batch很小時,作者有兩點猜測:這可能是因為caffe與TensorFlow在多GPU上傳播更新梯度的策略不同所致(sum vs mean across batches and GPUs);或者這是由於paper團隊使用了clip梯度的方式規避了梯度爆照的發生,但是作者提到他采用的clipping操作效果並不顯著。

安裝工程

1、Install dependencies

pip3 install -r requirements.txt

2、Clone this repository

3、Run setup from the repository root directory

python3 setup.py install

4、Download pre-trained COCO weights (mask_rcnn_coco.h5) from the releases page.

5、(Optional) To train or test on MS COCO install pycocotools from one of these repos. They are forks of the original pycocotools with fixes for Python3 and Windows (the official repo doesn't seem to be active anymore).

最后,作者展示了幾個使用了本框架的工程,這里不再引用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM