本文主要介绍Mask R-CNN的配置和测试需要配置CUDA8.0、cuDNN6.0.21、Python2、Caffe2、Detectron(CPU支持不完善)、COCO API。
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
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
pip install numpy pyyaml matplotlib opencv-python>=3.0 setuptools Cython mock
# 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=/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
使用本地图像运行效果演示,使用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为最后一个参数,为图片所在文件夹路径。
使用来源于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