Mask R-CNN安装及测试(Caffe2&Detectron&cocoAPI&Mask R-CNN)

Mask R-CNN 配置说明

概述:

本文主要介绍Mask R-CNN的配置和测试需要配置CUDA8.0、cuDNN6.0.21、Python2、Caffe2、Detectron(CPU支持不完善)、COCO API。

Caffe2安装(cuda和cudnn略)

依赖关系:

for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends libgflags2
for Ubuntu 16.04
sudo apt-get install -y --no-install-recommends libgflags-dev
for both Ubuntu 14.04 and 16.04
 sudo apt-get install -y --no-install-recommends \
       libgtest-dev \
       libiomp-dev \
       libleveldb-dev \
       liblmdb-dev \
       libopencv-dev \
       libopenmpi-dev \
       libsnappy-dev \
       openmpi-bin \
       openmpi-doc \
       python-pydot
 sudo pip install \
       flask \
       future \
       graphviz \
       hypothesis \
       jupyter \
       matplotlib \
       pydot python-nvd3 \
       pyyaml \
       requests \
       scikit-image \
       scipy \
       setuptools \
       six \
       tornado

下载并编译caffe2

git clone --recursive https://github.com/caffe2/caffe2.git
cd caffe2

编译

make
cd build && make install DESTDIR=/path/to/install

注:其中/path/to/install为安装路径,有sudo权限可使用sudo make install 可安装到/usr/local/下

验证是否安装成功

python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"

输出Success即成功

验证GPU构建

python2 -c 'from caffe2.python import workspace; print(workspace.NumCudaDevices())'

输出GPU数量即成功

加入环境变量

echo $PYTHONPATH
# export PYTHONPATH=/path/to/install/caffe2:$PYTHONPATH  #make install的路径
# export PYTHONPATH=$PYTHONPATH: /path/to/caffe2/build  #Caffe2源码路径
echo $LD_LIBRARY_PATH
# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

另外的依赖

Python依赖

pip install numpy pyyaml matplotlib opencv-python>=3.0 setuptools Cython mock

COCO API

# COCOAPI=/path/to/clone/cocoapi
git clone https://github.com/cocodataset/cocoapi.git $COCOAPI
cd $COCOAPI/PythonAPI
# 安装到全局第三方库中
make install
# Alternatively, if you do not have permissions or prefer
# 安装到用户Python库中
python2 setup.py install --user

Detectron安装

下载Detectron源码

# DETECTRON=/path/to/clone/detectron
git clone https://github.com/facebookresearch/detectron $DETECTRON
Set up Python modules:

编译:

cd $DETECTRON/lib && make

测试是否安装成功

python2 $DETECTRON/tests/test_spatial_narrow_as_op.py

输出如下即成功

Ran 3 tests in 7.049s
OK

使用Mask R-CNN演示

使用本地图像运行效果演示,使用tools/infer_simple.py,此例使用ResNet-101-FPN的Mask R-CNN作为模型。

python2 tools/infer_simple.py \
 --cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \
 --output-dir /tmp/detectron-visualizations \
 --image-ext jpg \
 --wts https://s3-us-west2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \
 demo

注:–cfg为模型路径,–output-dir为输出路径 默认为’/tmp/infer_simple’,结果将会以pdf的形式输出在指定目录下;–image-ext为图片格式,默认为jpg格式;–wts为网络权重文件;demo为最后一个参数,为图片所在文件夹路径。

Mask R-CNN测试

使用来源于model zoo的end2end Mask R-CNN网络进行COCO_2014_minival中图片的测试

python2 tools/test_net.py \
    --cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \
    --multi-gpu-testing \
    TEST.WEIGHTS https://s3-us-west-2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \
    NUM_GPUS 2

NUM_GPUS为使用GPU数量,测试结果如下

INFO json_dataset_evaluator.py: 232: ~~~~ Summary metrics ~~~~
  Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.364
  Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.585
  Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.387
  Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.166
  Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.392
  Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.540
  Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.303
  Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.459
  Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.478
  Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.266
  Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.520
  Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.642
 INFO json_dataset_evaluator.py: 122: Wrote json eval results to:./test/coco_2014_minival/generalized_rcnn/segmentation_results.pkl
 INFO task_evaluation.py:  65: Evaluating segmentations is done!
 INFO task_evaluation.py: 180: copypaste: Dataset: coco_2014_minival
 INFO task_evaluation.py: 182: copypaste: Task: box
 INFO task_evaluation.py: 185: copypaste: AP,AP50,AP75,APs,APm,APl
 INFO task_evaluation.py: 186: copypaste: 0.4089,0.6193,0.4478,0.2350,0.4421,0.5389
 INFO task_evaluation.py: 182: copypaste: Task: mask
 INFO task_evaluation.py: 185: copypaste: AP,AP50,AP75,APs,APm,APl
 INFO task_evaluation.py: 186: copypaste: 0.3639,0.5846,0.3869,0.1664,0.3915,0.5400

参考链接:

Caffe2_install

https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile

Detectron_github

https://github.com/facebookresearch/Detectron

Detectron_install

https://github.com/facebookresearch/Detectron/blob/master/INSTALL.md

Detectron_started

https://github.com/facebookresearch/Detectron/blob/master/GETTING_STARTED.md

COOC_API

https://github.com/cocodataset/cocoapi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值