zoukankan      html  css  js  c++  java
  • 『计算机视觉』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).

    最后,作者展示了几个使用了本框架的工程,这里不再引用。

  • 相关阅读:
    SpringMVC中@Controller和@RequestMapping用法和其他常用注解
    eclipse maven install 时控制台乱码问题解决
    使用模板实现编译期间多态(类名当参数)
    QT中Dialog的使用(使用QStackedWidget维护页面切换)
    QT中的各种对话框
    Qt 5 最小构建笔记(只编译QtBase)
    忽然懂了:“视图”的用途不仅仅是临时表,更适用于变化比较大的情况,而且不用改客户端一行代码
    React-Native
    一位OWin服务器新成员TinyFox
    Access Toke调用受保护的API
  • 原文地址:https://www.cnblogs.com/hellcat/p/9759328.html
Copyright © 2011-2022 走看看