maskrcnn无法生成训练文件_PaddlePaddle经典实例分割模型Mask RCNN

简介
区域卷积神经网络(RCNN)系列模型为两阶段目标检测器。通过对图像生成候选区域,提取特征,判别特征类别并修正候选框位置。 RCNN系列目前包含两个代表模型:Faster RCNN,Mask RCNN
Faster RCNN 整体网络可以分为4个主要内容:

  1. 基础卷积层。作为一种卷积神经网络目标检测方法,Faster RCNN首先使用一组基础的卷积网络提取图像的特征图。特征图被后续RPN层和全连接层共享。本示例采用ResNet-50作为基础卷积层。
  2. 区域生成网络(RPN)。RPN网络用于生成候选区域(proposals)。该层通过一组固定的尺寸和比例得到一组锚点(anchors), 通过softmax判断锚点属于前景或者背景,再利用区域回归修正锚点从而获得精确的候选区域。
  3. RoI Align。该层收集输入的特征图和候选区域,将候选区域映射到特征图中并池化为统一大小的区域特征图,送入全连接层判定目标类别, 该层可选用RoIPool和RoIAlign两种方式,在config.py中设置roi_func。
  4. 检测层。利用区域特征图计算候选区域的类别,同时再次通过区域回归获得检测框最终的精确位置。

Mask RCNN 扩展自Faster RCNN,是经典的实例分割模型。
Mask RCNN同样为两阶段框架,第一阶段扫描图像生成候选框;第二阶段根据候选框得到分类结果,边界框,同时在原有Faster RCNN模型基础上添加分割分支,得到掩码结果,实现了掩码和类别预测关系的解藕。
本例采用COCO数据集的子集,即随机从COCO大数据集中选取30张图组成coco30数据集,数据存放在rcnn/coco30。 本例采用coco30,可通过修改--data_dir修改训练集.
Mask RCNN结构图如下:

526b5ea98d7d9cbab01d71b82d1ac9f6.png


注:本例默认用GPU运行,也可通过设置--use_gpu=False使用CPU设备。


阅读本项目之前建议阅读mask-rcnn原版论文https://arxiv.org/abs/1703.06870 相关优秀博客https://blog.csdn.net/WZZ18191171661/article/details/79453780
本例采用COCO数据集的子集,即随机从COCO大数据集中选取30张图组成coco30数据集,数据存放在rcnn/coco30。 本例采用coco30,可通过修改--data_dir修改训练集.COCO数据集介绍:https://blog.csdn.net/wc781708249/article/details/79603522
文件夹介绍:
1.models:构造模型主体的函数
2.coco30: 训练数据集
3.output: 保存训练模型
4:imagenet_resnet50_fusebn: 存放预训练模型
所有执行文件均在mask-rcnn文件夹内,在了解mask-rcnn基本原理的基础上,建议阅读顺序:
1.models文件夹:存放模型主体构造以及loss构造相关文件。
2.utility.py、config.py: 训练相关参数设置。
3.readers.py: 训练数据格式构造。
4.train.py:训练主体程序。
5.其他相关辅助函数

#安装CocoAPI
#!git clone https://github.com/cocodataset/cocoapi.git
!cd cocoapi/PythonAPI && make install

# install pycocotools to the Python site-packages
python setup.py build_ext install
running build_ext
skipping 'pycocotools/_mask.c' Cython extension (up-to-date)
building 'pycocotools._mask' extension
creating build
creating build/common
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/pycocotools
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -m64 -fPIC -fPIC -I/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/numpy/core/include -I../common -I/opt/conda/envs/python35-paddle120-env/include/python3.5m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.5/../common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99../common/maskApi.c: In function ‘rleToBbox’:../common/maskApi.c:141:31: warning: xp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if(j%2==0) xp=x; else if(xp<x) { ys=0; ye=h-1; } ^
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -m64 -fPIC -fPIC -I/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/numpy/core/include -I../common -I/opt/conda/envs/python35-paddle120-env/include/python3.5m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/pycocotools
gcc -pthread -shared -L/opt/conda/envs/python35-paddle120-env/lib -Wl,-rpath=/opt/conda/envs/python35-paddle120-env/lib,--no-as-needed build/temp.linux-x86_64-3.5/../common/maskApi.o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -L/opt/conda/envs/python35-paddle120-env/lib -lpython3.5m -o build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
running install
running bdist_egg
running egg_info
writing pycocotools.egg-info/PKG-INFO
writing dependency_links to pycocotools.egg-info/dependency_links.txt
writing top-level names to pycocotools.egg-info/top_level.txt
writing requirements to pycocotools.egg-info/requires.txt
reading manifest file 'pycocotools.egg-info/SOURCES.txt'
writing manifest file 'pycocotools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying pycocotools/coco.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/mask.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.5/pycocotools
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/coco.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/cocoeval.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/mask.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/__init__.py -> build/bdist.linux-x86_64/egg/pycocotools
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/coco.py to coco.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/cocoeval.py to cocoeval.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/mask.py to mask.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/__init__.py to __init__.cpython-35.pyc
creating stub loader for pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/_mask.py to _mask.cpython-35.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
pycocotools.__pycache__._mask.cpython-35: module references __file__
creating 'dist/pycocotools-2.0-py3.5-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pycocotools-2.0-py3.5-linux-x86_64.egg
creating /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/pycocotools-2.0-py3.5-linux-x86_64.egg
Extracting pycocotools-2.0-py3.5-linux-x86_64.egg to /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Adding pycocotools 2.0 to easy-install.pth file
Installed /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/pycocotools-2.0-py3.5-linux-x86_64.egg
Processing dependencies for pycocotools==2.0
Searching for matplotlib==2.2.3
Best match: matplotlib 2.2.3
Adding matplotlib 2.2.3 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for Cython==0.29.10
Best match: Cython 0.29.10
Adding Cython 0.29.10 to easy-install.pth file
Installing cythonize script to /opt/conda/envs/python35-paddle120-env/bin
Installing cython script to /opt/conda/envs/python35-paddle120-env/bin
Installing cygdb script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for setuptools==40.4.3
Best match: setuptools 40.4.3
Adding setuptools 40.4.3 to easy-install.pth file
Installing easy_install script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for numpy==1.16.4
Best match: numpy 1.16.4
Adding numpy 1.16.4 to easy-install.pth file
Installing f2py3.5 script to /opt/conda/envs/python35-paddle120-env/bin
Installing f2py3 script to /opt/conda/envs/python35-paddle120-env/bin
Installing f2py script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for pyparsing==2.4.0
Best match: pyparsing 2.4.0
Adding pyparsing 2.4.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for python-dateutil==2.8.0
Best match: python-dateutil 2.8.0
Adding python-dateutil 2.8.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for pytz==2019.1
Best match: pytz 2019.1
Adding pytz 2019.1 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for six==1.11.0
Best match: six 1.11.0
Adding six 1.11.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for kiwisolver==1.1.0
Best match: kiwisolver 1.1.0
Adding kiwisolver 1.1.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for cycler==0.10.0
Best match: cycler 0.10.0
Adding cycler 0.10.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Finished processing dependencies for pycocotools==2.0
rm -rf build# install pycocotools to the Python site-packages
python setup.py build_ext install
running build_ext
skipping 'pycocotools/_mask.c' Cython extension (up-to-date)
building 'pycocotools._mask' extension
creating build
creating build/common
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/pycocotools
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -m64 -fPIC -fPIC -I/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/numpy/core/include -I../common -I/opt/conda/envs/python35-paddle120-env/include/python3.5m -c ../common/maskApi.c -o build/temp.linux-x86_64-3.5/../common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99../common/maskApi.c: In function ‘rleToBbox’:../common/maskApi.c:141:31: warning: xp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
if(j%2==0) xp=x; else if(xp<x) { ys=0; ye=h-1; } ^
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -m64 -fPIC -fPIC -I/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/numpy/core/include -I../common -I/opt/conda/envs/python35-paddle120-env/include/python3.5m -c pycocotools/_mask.c -o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
creating build/lib.linux-x86_64-3.5
creating build/lib.linux-x86_64-3.5/pycocotools
gcc -pthread -shared -L/opt/conda/envs/python35-paddle120-env/lib -Wl,-rpath=/opt/conda/envs/python35-paddle120-env/lib,--no-as-needed build/temp.linux-x86_64-3.5/../common/maskApi.o build/temp.linux-x86_64-3.5/pycocotools/_mask.o -L/opt/conda/envs/python35-paddle120-env/lib -lpython3.5m -o build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
running install
running bdist_egg
running egg_info
writing pycocotools.egg-info/PKG-INFO
writing dependency_links to pycocotools.egg-info/dependency_links.txt
writing top-level names to pycocotools.egg-info/top_level.txt
writing requirements to pycocotools.egg-info/requires.txt
reading manifest file 'pycocotools.egg-info/SOURCES.txt'
writing manifest file 'pycocotools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying pycocotools/coco.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/mask.py -> build/lib.linux-x86_64-3.5/pycocotools
copying pycocotools/__init__.py -> build/lib.linux-x86_64-3.5/pycocotools
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/coco.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/cocoeval.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/mask.py -> build/bdist.linux-x86_64/egg/pycocotools
copying build/lib.linux-x86_64-3.5/pycocotools/__init__.py -> build/bdist.linux-x86_64/egg/pycocotools
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/coco.py to coco.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/cocoeval.py to cocoeval.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/mask.py to mask.cpython-35.pyc
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/__init__.py to __init__.cpython-35.pyc
creating stub loader for pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/pycocotools/_mask.py to _mask.cpython-35.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pycocotools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
pycocotools.__pycache__._mask.cpython-35: module references __file__
creating 'dist/pycocotools-2.0-py3.5-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pycocotools-2.0-py3.5-linux-x86_64.egg
creating /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/pycocotools-2.0-py3.5-linux-x86_64.egg
Extracting pycocotools-2.0-py3.5-linux-x86_64.egg to /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Adding pycocotools 2.0 to easy-install.pth file
Installed /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/pycocotools-2.0-py3.5-linux-x86_64.egg
Processing dependencies for pycocotools==2.0
Searching for matplotlib==2.2.3
Best match: matplotlib 2.2.3
Adding matplotlib 2.2.3 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for Cython==0.29.10
Best match: Cython 0.29.10
Adding Cython 0.29.10 to easy-install.pth file
Installing cythonize script to /opt/conda/envs/python35-paddle120-env/bin
Installing cython script to /opt/conda/envs/python35-paddle120-env/bin
Installing cygdb script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for setuptools==40.4.3
Best match: setuptools 40.4.3
Adding setuptools 40.4.3 to easy-install.pth file
Installing easy_install script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for numpy==1.16.4
Best match: numpy 1.16.4
Adding numpy 1.16.4 to easy-install.pth file
Installing f2py3.5 script to /opt/conda/envs/python35-paddle120-env/bin
Installing f2py3 script to /opt/conda/envs/python35-paddle120-env/bin
Installing f2py script to /opt/conda/envs/python35-paddle120-env/bin
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for pyparsing==2.4.0
Best match: pyparsing 2.4.0
Adding pyparsing 2.4.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for python-dateutil==2.8.0
Best match: python-dateutil 2.8.0
Adding python-dateutil 2.8.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for pytz==2019.1
Best match: pytz 2019.1
Adding pytz 2019.1 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for six==1.11.0
Best match: six 1.11.0
Adding six 1.11.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for kiwisolver==1.1.0
Best match: kiwisolver 1.1.0
Adding kiwisolver 1.1.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Searching for cycler==0.10.0
Best match: cycler 0.10.0
Adding cycler 0.10.0 to easy-install.pth file
Using /opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages
Finished processing dependencies for pycocotools==2.0
rm -rf build

#模型训练
!cd mask-rcnn && python train.py 
   --model_save_dir=output/ 
   --pretrained_model=imagenet_resnet50_fusebn 
   --data_dir=coco30 
   --max_iter=3000 
   --use_gpu=True 
   --MASK_ON=True

----------- Configuration Arguments -----------
MASK_ON: 1
anchor_sizes: [32, 64, 128, 256, 512]
aspect_ratios: [0.5, 1.0, 2.0]
batch_size_per_im: 512
class_num: 81
data_dir: coco30
dataset: coco2017
draw_threshold: 0.8
enable_ce: False
freeze_model_save_dir: freeze_model
im_per_batch: 1
image_path: dataset/coco/val2017
learning_rate: 0.01
log_window: 20
max_iter: 3000
max_size: 1333
model_save_dir: output/
nms_thresh: 0.5
padding_minibatch: False
parallel: False
pixel_means: [102.9801, 115.9465, 122.7717]
pretrained_model: imagenet_resnet50_fusebn
rpn_nms_thresh: 0.7
rpn_stride: [16.0, 16.0]
scales: [800]
score_thresh: 0.05
snapshot_stride: 10000
use_gpu: 1
use_profile: False
use_pyreader: False
variance: [1.0, 1.0, 1.0, 1.0]
------------------------------------------------
W0828 10:16:38.641909 212 http://device_context.cc:259] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0828 10:16:38.646142 212 http://device_context.cc:267] device: 0, cuDNN Version: 7.3.
Creating: coco2017
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
_add_gt_annotations took 0.009s
Appending horizontally-flipped training examples...
Loaded dataset: coco2017
60 roidb entries
Filtered 0 roidb entries: 60 -> 60
train on coco2017 with 60 roidbs
2019-08-28 10:16:40.598017, iter: 0, lr: 0.00333, 'loss_cls': 4.417, 'loss_mask': 1.109, 'loss_bbox': 0.128, 'loss': 6.569, 'loss_rpn_bbox': 0.216, 'loss_rpn_cls': 0.699, time: 0.018
2019-08-28 10:16:56.832567, iter: 50, lr: 0.00400, 'loss_cls': 0.431, 'loss_mask': 0.704, 'loss_bbox': 0.051, 'loss': 1.744, 'loss_rpn_bbox': 0.146, 'loss_rpn_cls': 0.425, time: 0.268
2019-08-28 10:17:13.274540, iter: 100, lr: 0.00467, 'loss_cls': 0.445, 'loss_mask': 0.656, 'loss_bbox': 0.092, 'loss': 1.783, 'loss_rpn_bbox': 0.205, 'loss_rpn_cls': 0.414, time: 0.297
2019-08-28 10:17:29.150029, iter: 150, lr: 0.00533, 'loss_cls': 0.51, 'loss_mask': 0.645, 'loss_bbox': 0.146, 'loss': 1.855, 'loss_rpn_bbox': 0.165, 'loss_rpn_cls': 0.346, time: 0.300
2019-08-28 10:17:46.438505, iter: 200, lr: 0.00600, 'loss_cls': 0.366, 'loss_mask': 0.623, 'loss_bbox': 0.115, 'loss': 1.583, 'loss_rpn_bbox': 0.156, 'loss_rpn_cls': 0.323, time: 0.283
2019-08-28 10:18:02.917941, iter: 250, lr: 0.00667, 'loss_cls': 0.495, 'loss_mask': 0.612, 'loss_bbox': 0.138, 'loss': 1.737, 'loss_rpn_bbox': 0.155, 'loss_rpn_cls': 0.382, time: 0.314
2019-08-28 10:18:20.530741, iter: 300, lr: 0.00733, 'loss_cls': 0.44, 'loss_mask': 0.591, 'loss_bbox': 0.137, 'loss': 1.616, 'loss_rpn_bbox': 0.132, 'loss_rpn_cls': 0.301, time: 0.358
2019-08-28 10:18:37.671191, iter: 350, lr: 0.00800, 'loss_cls': 0.44, 'loss_mask': 0.564, 'loss_bbox': 0.156, 'loss': 1.59, 'loss_rpn_bbox': 0.139, 'loss_rpn_cls': 0.247, time: 0.377
2019-08-28 10:18:54.597628, iter: 400, lr: 0.00867, 'loss_cls': 0.568, 'loss_mask': 0.591, 'loss_bbox': 0.244, 'loss': 1.738, 'loss_rpn_bbox': 0.104, 'loss_rpn_cls': 0.266, time: 0.349
2019-08-28 10:19:11.880430, iter: 450, lr: 0.00933, 'loss_cls': 0.538, 'loss_mask': 0.568, 'loss_bbox': 0.163, 'loss': 1.59, 'loss_rpn_bbox': 0.112, 'loss_rpn_cls': 0.27, time: 0.338
2019-08-28 10:19:29.210413, iter: 500, lr: 0.01000, 'loss_cls': 0.416, 'loss_mask': 0.543, 'loss_bbox': 0.17, 'loss': 1.557, 'loss_rpn_bbox': 0.105, 'loss_rpn_cls': 0.235, time: 0.337
2019-08-28 10:19:46.603084, iter: 550, lr: 0.01000, 'loss_cls': 0.57, 'loss_mask': 0.569, 'loss_bbox': 0.202, 'loss': 1.676, 'loss_rpn_bbox': 0.107, 'loss_rpn_cls': 0.246, time: 0.335
2019-08-28 10:20:04.189566, iter: 600, lr: 0.01000, 'loss_cls': 0.608, 'loss_mask': 0.512, 'loss_bbox': 0.213, 'loss': 1.727, 'loss_rpn_bbox': 0.053, 'loss_rpn_cls': 0.232, time: 0.336
2019-08-28 10:20:21.582167, iter: 650, lr: 0.01000, 'loss_cls': 0.571, 'loss_mask': 0.461, 'loss_bbox': 0.311, 'loss': 1.773, 'loss_rpn_bbox': 0.167, 'loss_rpn_cls': 0.192, time: 0.346
2019-08-28 10:20:39.112590, iter: 700, lr: 0.01000, 'loss_cls': 0.547, 'loss_mask': 0.462, 'loss_bbox': 0.225, 'loss': 1.477, 'loss_rpn_bbox': 0.086, 'loss_rpn_cls': 0.157, time: 0.348
2019-08-28 10:20:56.749053, iter: 750, lr: 0.01000, 'loss_cls': 0.535, 'loss_mask': 0.471, 'loss_bbox': 0.226, 'loss': 1.483, 'loss_rpn_bbox': 0.084, 'loss_rpn_cls': 0.155, time: 0.338
2019-08-28 10:21:14.991664, iter: 800, lr: 0.01000, 'loss_cls': 0.488, 'loss_mask': 0.544, 'loss_bbox': 0.204, 'loss': 1.657, 'loss_rpn_bbox': 0.107, 'loss_rpn_cls': 0.203, time: 0.377
2019-08-28 10:21:33.416243, iter: 850, lr: 0.01000, 'loss_cls': 0.57, 'loss_mask': 0.464, 'loss_bbox': 0.31, 'loss': 1.638, 'loss_rpn_bbox': 0.077, 'loss_rpn_cls': 0.138, time: 0.380
2019-08-28 10:21:51.716017, iter: 900, lr: 0.01000, 'loss_cls': 0.725, 'loss_mask': 0.515, 'loss_bbox': 0.3, 'loss': 1.88, 'loss_rpn_bbox': 0.087, 'loss_rpn_cls': 0.175, time: 0.549
2019-08-28 10:22:10.090252, iter: 950, lr: 0.01000, 'loss_cls': 0.632, 'loss_mask': 0.464, 'loss_bbox': 0.261, 'loss': 1.581, 'loss_rpn_bbox': 0.048, 'loss_rpn_cls': 0.121, time: 0.364
2019-08-28 10:22:28.691718, iter: 1000, lr: 0.01000, 'loss_cls': 0.595, 'loss_mask': 0.426, 'loss_bbox': 0.315, 'loss': 1.485, 'loss_rpn_bbox': 0.071, 'loss_rpn_cls': 0.115, time: 0.364
2019-08-28 10:22:46.478322, iter: 1050, lr: 0.01000, 'loss_cls': 0.56, 'loss_mask': 0.395, 'loss_bbox': 0.316, 'loss': 1.45, 'loss_rpn_bbox': 0.069, 'loss_rpn_cls': 0.096, time: 0.344
2019-08-28 10:23:04.306094, iter: 1100, lr: 0.01000, 'loss_cls': 0.547, 'loss_mask': 0.416, 'loss_bbox': 0.314, 'loss': 1.533, 'loss_rpn_bbox': 0.098, 'loss_rpn_cls': 0.13, time: 0.333
2019-08-28 10:23:22.653763, iter: 1150, lr: 0.01000, 'loss_cls': 0.433, 'loss_mask': 0.393, 'loss_bbox': 0.318, 'loss': 1.288, 'loss_rpn_bbox': 0.046, 'loss_rpn_cls': 0.083, time: 0.359
2019-08-28 10:23:40.920892, iter: 1200, lr: 0.01000, 'loss_cls': 0.527, 'loss_mask': 0.392, 'loss_bbox': 0.352, 'loss': 1.394, 'loss_rpn_bbox': 0.066, 'loss_rpn_cls': 0.097, time: 0.361
2019-08-28 10:23:59.175570, iter: 1250, lr: 0.01000, 'loss_cls': 0.556, 'loss_mask': 0.415, 'loss_bbox': 0.347, 'loss': 1.466, 'loss_rpn_bbox': 0.049, 'loss_rpn_cls': 0.078, time: 0.359
2019-08-28 10:24:17.054893, iter: 1300, lr: 0.01000, 'loss_cls': 0.482, 'loss_mask': 0.371, 'loss_bbox': 0.355, 'loss': 1.29, 'loss_rpn_bbox': 0.051, 'loss_rpn_cls': 0.063, time: 0.545
2019-08-28 10:24:35.260912, iter: 1350, lr: 0.01000, 'loss_cls': 0.396, 'loss_mask': 0.348, 'loss_bbox': 0.287, 'loss': 1.127, 'loss_rpn_bbox': 0.059, 'loss_rpn_cls': 0.051, time: 0.369
2019-08-28 10:24:53.680534, iter: 1400, lr: 0.01000, 'loss_cls': 0.447, 'loss_mask': 0.35, 'loss_bbox': 0.295, 'loss': 1.205, 'loss_rpn_bbox': 0.068, 'loss_rpn_cls': 0.064, time: 0.381
2019-08-28 10:25:11.668375, iter: 1450, lr: 0.01000, 'loss_cls': 0.614, 'loss_mask': 0.402, 'loss_bbox': 0.348, 'loss': 1.486, 'loss_rpn_bbox': 0.046, 'loss_rpn_cls': 0.081, time: 0.362
2019-08-28 10:25:29.691196, iter: 1500, lr: 0.01000, 'loss_cls': 0.531, 'loss_mask': 0.358, 'loss_bbox': 0.302, 'loss': 1.287, 'loss_rpn_bbox': 0.065, 'loss_rpn_cls': 0.053, time: 0.352
2019-08-28 10:25:48.003211, iter: 1550, lr: 0.01000, 'loss_cls': 0.394, 'loss_mask': 0.329, 'loss_bbox': 0.339, 'loss': 1.168, 'loss_rpn_bbox': 0.069, 'loss_rpn_cls': 0.056, time: 0.351
2019-08-28 10:26:06.506278, iter: 1600, lr: 0.01000, 'loss_cls': 0.313, 'loss_mask': 0.303, 'loss_bbox': 0.27, 'loss': 0.953, 'loss_rpn_bbox': 0.058, 'loss_rpn_cls': 0.041, time: 0.348
2019-08-28 10:26:24.911350, iter: 1650, lr: 0.01000, 'loss_cls': 0.358, 'loss_mask': 0.319, 'loss_bbox': 0.332, 'loss': 1.089, 'loss_rpn_bbox': 0.059, 'loss_rpn_cls': 0.041, time: 0.361
2019-08-28 10:26:43.280922, iter: 1700, lr: 0.01000, 'loss_cls': 0.343, 'loss_mask': 0.297, 'loss_bbox': 0.267, 'loss': 1.029, 'loss_rpn_bbox': 0.043, 'loss_rpn_cls': 0.04, time: 0.365
2019-08-28 10:27:01.706950, iter: 1750, lr: 0.01000, 'loss_cls': 0.257, 'loss_mask': 0.249, 'loss_bbox': 0.183, 'loss': 0.818, 'loss_rpn_bbox': 0.034, 'loss_rpn_cls': 0.027, time: 0.370
2019-08-28 10:27:20.418963, iter: 1800, lr: 0.01000, 'loss_cls': 0.385, 'loss_mask': 0.317, 'loss_bbox': 0.305, 'loss': 1.098, 'loss_rpn_bbox': 0.044, 'loss_rpn_cls': 0.045, time: 0.396
2019-08-28 10:27:38.672954, iter: 1850, lr: 0.01000, 'loss_cls': 0.313, 'loss_mask': 0.318, 'loss_bbox': 0.237, 'loss': 0.931, 'loss_rpn_bbox': 0.042, 'loss_rpn_cls': 0.032, time: 0.375
2019-08-28 10:27:56.875251, iter: 1900, lr: 0.01000, 'loss_cls': 0.304, 'loss_mask': 0.306, 'loss_bbox': 0.274, 'loss': 0.902, 'loss_rpn_bbox': 0.062, 'loss_rpn_cls': 0.044, time: 0.364
2019-08-28 10:28:15.098122, iter: 1950, lr: 0.01000, 'loss_cls': 0.386, 'loss_mask': 0.291, 'loss_bbox': 0.294, 'loss': 1.03, 'loss_rpn_bbox': 0.041, 'loss_rpn_cls': 0.035, time: 0.364
2019-08-28 10:28:33.250704, iter: 2000, lr: 0.01000, 'loss_cls': 0.312, 'loss_mask': 0.28, 'loss_bbox': 0.259, 'loss': 0.941, 'loss_rpn_bbox': 0.042, 'loss_rpn_cls': 0.025, time: 0.337
2019-08-28 10:28:51.688948, iter: 2050, lr: 0.01000, 'loss_cls': 0.226, 'loss_mask': 0.244, 'loss_bbox': 0.215, 'loss': 0.726, 'loss_rpn_bbox': 0.03, 'loss_rpn_cls': 0.024, time: 0.343
2019-08-28 10:29:10.119525, iter: 2100, lr: 0.01000, 'loss_cls': 0.233, 'loss_mask': 0.275, 'loss_bbox': 0.283, 'loss': 0.885, 'loss_rpn_bbox': 0.042, 'loss_rpn_cls': 0.032, time: 0.364
2019-08-28 10:29:28.423118, iter: 2150, lr: 0.01000, 'loss_cls': 0.216, 'loss_mask': 0.254, 'loss_bbox': 0.208, 'loss': 0.714, 'loss_rpn_bbox': 0.034, 'loss_rpn_cls': 0.025, time: 0.366
2019-08-28 10:29:47.098226, iter: 2200, lr: 0.01000, 'loss_cls': 0.273, 'loss_mask': 0.278, 'loss_bbox': 0.215, 'loss': 0.84, 'loss_rpn_bbox': 0.058, 'loss_rpn_cls': 0.032, time: 0.343
2019-08-28 10:30:05.369391, iter: 2250, lr: 0.01000, 'loss_cls': 0.237, 'loss_mask': 0.221, 'loss_bbox': 0.221, 'loss': 0.737, 'loss_rpn_bbox': 0.028, 'loss_rpn_cls': 0.02, time: 0.352
2019-08-28 10:30:23.709169, iter: 2300, lr: 0.01000, 'loss_cls': 0.301, 'loss_mask': 0.255, 'loss_bbox': 0.253, 'loss': 0.891, 'loss_rpn_bbox': 0.032, 'loss_rpn_cls': 0.024, time: 0.387
2019-08-28 10:30:41.909947, iter: 2350, lr: 0.01000, 'loss_cls': 0.234, 'loss_mask': 0.256, 'loss_bbox': 0.15, 'loss': 0.627, 'loss_rpn_bbox': 0.035, 'loss_rpn_cls': 0.017, time: 0.373
2019-08-28 10:30:59.774337, iter: 2400, lr: 0.01000, 'loss_cls': 0.175, 'loss_mask': 0.216, 'loss_bbox': 0.198, 'loss': 0.677, 'loss_rpn_bbox': 0.03, 'loss_rpn_cls': 0.023, time: 0.368
2019-08-28 10:31:17.912704, iter: 2450, lr: 0.01000, 'loss_cls': 0.205, 'loss_mask': 0.215, 'loss_bbox': 0.205, 'loss': 0.684, 'loss_rpn_bbox': 0.025, 'loss_rpn_cls': 0.018, time: 0.386
2019-08-28 10:31:36.230056, iter: 2500, lr: 0.01000, 'loss_cls': 0.182, 'loss_mask': 0.23, 'loss_bbox': 0.201, 'loss': 0.656, 'loss_rpn_bbox': 0.025, 'loss_rpn_cls': 0.018, time: 0.374
2019-08-28 10:31:54.746713, iter: 2550, lr: 0.01000, 'loss_cls': 0.163, 'loss_mask': 0.217, 'loss_bbox': 0.165, 'loss': 0.604, 'loss_rpn_bbox': 0.034, 'loss_rpn_cls': 0.015, time: 0.337
2019-08-28 10:32:13.348275, iter: 2600, lr: 0.01000, 'loss_cls': 0.139, 'loss_mask': 0.197, 'loss_bbox': 0.154, 'loss': 0.556, 'loss_rpn_bbox': 0.035, 'loss_rpn_cls': 0.02, time: 0.361
2019-08-28 10:32:31.558732, iter: 2650, lr: 0.01000, 'loss_cls': 0.188, 'loss_mask': 0.23, 'loss_bbox': 0.176, 'loss': 0.669, 'loss_rpn_bbox': 0.039, 'loss_rpn_cls': 0.026, time: 0.327
2019-08-28 10:32:49.654740, iter: 2700, lr: 0.01000, 'loss_cls': 0.193, 'loss_mask': 0.261, 'loss_bbox': 0.239, 'loss': 0.787, 'loss_rpn_bbox': 0.031, 'loss_rpn_cls': 0.031, time: 0.336
2019-08-28 10:33:25.747055, iter: 2800, lr: 0.01000, 'loss_cls': 0.155, 'loss_mask': 0.218, 'loss_bbox': 0.178, 'loss': 0.626, 'loss_rpn_bbox': 0.032, 'loss_rpn_cls': 0.026, time: 0.380
2019-08-28 10:33:44.111608, iter: 2850, lr: 0.01000, 'loss_cls': 0.125, 'loss_mask': 0.225, 'loss_bbox': 0.128, 'loss': 0.508, 'loss_rpn_bbox': 0.023, 'loss_rpn_cls': 0.017, time: 0.361
2019-08-28 10:34:02.944465, iter: 2900, lr: 0.01000, 'loss_cls': 0.143, 'loss_mask': 0.2, 'loss_bbox': 0.171, 'loss': 0.563, 'loss_rpn_bbox': 0.049, 'loss_rpn_cls': 0.015, time: 0.374
2019-08-28 10:34:21.538064, iter: 2950, lr: 0.01000, 'loss_cls': 0.114, 'loss_mask': 0.184, 'loss_bbox': 0.111, 'loss': 0.481, 'loss_rpn_bbox': 0.026, 'loss_rpn_cls': 0.013, time: 0.391

#固化模型
!cd mask-rcnn && python freeze_model.py 
                   --pretrained_model=output/model_final 
                   --freeze_model_save_dir=freeze_model 
                   --use_gpu=1

The COCO dataset or COCO API is not exist, use the default mapping of class index and real category name on COCO17.
W0828 10:36:57.041860 304 http://device_context.cc:259] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0828 10:36:57.046031 304 http://device_context.cc:267] device: 0, cuDNN Version: 7.3.
freeze succeed

#利用固化的模型进行预测
!cd mask-rcnn && python freeze_infer.py 
                  --image_path=coco30/train2017/000000005802.jpg  
                  --draw_threshold=0.7 
                  --use_gpu=1

######检测结果可视化
%matplotlib inline   
import matplotlib.pyplot as plt  
import numpy as np
import cv2

detect_img= cv2.imread('mask-rcnn/000000005802.jpg')

plt.imshow(detect_img)
plt.show()

The COCO dataset or COCO API is not exist, use the default mapping of class index and real category name on COCO17.
W0828 10:37:06.034216 373 http://device_context.cc:259] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 9.2, Runtime API Version: 9.0
W0828 10:37:06.038113 373 http://device_context.cc:267] device: 0, cuDNN Version: 7.3.
image with bbox drawed saved as 000000005802.jpg

cca992e9f9de486bebcb5c3a3d9ca4d5.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Mask R-CNN是一种目标检测算法,它利用了Faster R-CNN结构以及先前的Mask R-CNN架构,可以完成实例分割任务。这种算法不仅可以检测出图像中的物体位置,还可以推断出每个物体的组成部分。可以对具有不同形状和大小的物体进行有效的分割。 在训练Mask R-CNN算法进行实例分割时,我们需要提供一组有标注的图像。这些图像应当包含我们所感兴趣的物体,以及这些物体的位置和组成部分。在标记物体位置时,我们使用边界框将其框起来。 在Mask R-CNN的训练过程中,每张图片都会经过多个卷积和池化操作,用来提取其特征。在这个过程中,我们使用Focal Loss损失函数来计算每个预测框和其真实框之间的损失。当损失降到一定程度时,我们就可以通过算法来预测未标记的图片中的物体位置和组成部分。 与传统的目标检测算法不同的是,Mask R-CNN除了检测物体位置外,还利用全连接网络、卷积神经网络等技术对目标进行像素级的实例分割,可以获得更精确的物体识别结果。但Mask R-CNN模型拟合的难度比较大,需要多次迭代训练,以获得比较好的表现。 ### 回答2: Mask R-CNN是一种常用的实例分割算法,它结合了Faster R-CNN的目标检测Mask R-CNN的像素级别分割。使用Mask R-CNN进行实例分割训练可分为以下几个步骤: 1. 数据预处理:首先需要对训练数据进行预处理,包括图像的缩放、裁剪、数据增强等操作,以提高训练效果。 2. 网络搭建:Mask R-CNN主要由两部分组成,即Region Proposal Network(RPN)和Mask Head,其中RPN检测出潜在的目标区域,而Mask Head对目标区域进行像素级别分割。 3. 模型训练:使用预处理后的训练数据进行模型训练,可以选择使用预训练模型进行迁移学习,也可以从头开始训练训练过程中需要设置相应的学习率、loss函数等参数。 4. 模型评估:训练完成后需要对模型进行评估,使用测试数据来计算模型的准确率、召回率和F1分数等指标。 5. 模型应用:在模型评估完成后可以将其应用到实际场景中,进行实例分割任务。 值得注意的是,在实际应用中,可能需要对Mask R-CNN进行优化,以提高模型的效率和准确率。比如可以通过改变网络结构、增加训练数据量、使用更加有效的数据增强技术等方法来进行优化,以最大程度地提升模型性能。 ### 回答3: Mask R-CNN是一种基于Faster R-CNN的深度学习模型,具有强大的目标检测实例分割功能,广泛应用于计算机视觉领域。Mask R-CNN的训练过程需要进行多步骤,包括数据准备、模型配置、模型训练模型评估等。 首先,需要准备用于训练的数据集。Mask R-CNN适用于对各种类型目标进行检测和分割,因此需要包含大量样本,涵盖多种场景和各种目标类型。数据集准备过程中要注意对样本进行标注并存储为图像和对应的标签数据。 其次,需要配置Mask R-CNN模型。配置包括定义网络结构、选择优化器和设置超参数等。这里需要根据数据集情况选择合适的网络结构和优化器,并根据实际情况对超参数进行调整,以优化模型性能。 接下来,进行模型训练过程。训练过程可以分为两个阶段:目标检测阶段和实例分割阶段。在目标检测阶段中,将输入图像通过模型,输出目标检测框和对应的类别信息。在实例分割阶段中,通过对目标检测框进行细化处理,输出每个目标的像素级分割结果。 在训练过程中,可以使用预处理技术进行数据增强,以提高模型鲁棒性和泛化能力。同时采用提前终止技术避免模型过拟合,降低模型训练时间和成本。 最后,进行模型评估和优化。评估指标包括目标检测精度、实例分割精度和模型速度等。可以通过调整模型超参数和训练策略等方法来优化模型性能和训练效果。 总之,Mask R-CNN实例分割训练是一个复杂的过程,需要耗费大量的时间和资源。但通过合适的数据准备、模型配置、训练和评估等步骤,可以实现高质量的目标检测实例分割效果,为计算机视觉领域的应用提供强有力的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值