caffe2 环境的搭建以及detectron的配置
caffe2 环境的搭建以及detectron的配置
建议大家看一下这篇博客https://tech.amikelive.com/node-706/comprehensive-guide-installing-caffe2-with-gpu-support-by-building-from-source-on-ubuntu-16-04/?tdsourcetag=s_pctim_aiomsg,是属于比较新的博客,因为caffe2已经合并到pytorch了,所以某些内容已经并不适用了.
环境的安装
- 安装cuda9.0
- 安装cudnn7.0
按照官网的源码安装说明进行安装caffe2
https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile
使用anaconda3
, python2.7
- 安装需要的库
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
libgoogle-glog-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libopenmpi-dev \
libsnappy-dev \
libprotobuf-dev \
openmpi-bin \
openmpi-doc \
protobuf-compiler \
python-dev \
python-pip
sudo pip install \
future \
numpy \
protobuf
- libgflags2根据系统选择
# 对于 Ubuntu 14.04
sudo apt-get install -y --no-install-recommends libgflags2
# 对于 Ubuntu 16.04
sudo apt-get install -y --no-install-recommends libgflags-dev
- 下载
git clone --recursive https://github.com/caffe2/caffe2.git && cd caffe2
make && cd build && sudo make install
- 测试
测试caffe2是否安装成功
cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
如果是failure,试着cd到caffe2/build的文件夹里,然后执行
python -c 'from caffe2.python import core' 2>/dev/null
如果successful,说明是环境变量的设置问题,如果还是失败,则会有具体的提示。
配置环境变量,编辑~/.bashrc
sudo gedit ~/.bashrc
添加以下内容:
export PYTHONPATH=/usr/local:PYTHONPATH
export PYTHONPATH=PYTHONPATH:/home/....../caffe2/build (后面路径为caffe2的编译路径,在caffe2/build中,命令行输入pwd可以得到这个路径)
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
安装detectron
官方说明文档:https://github.com/facebookresearch/Detectron/blob/master/INSTALL.md
下载下来文件:
git clone https://github.com/facebookresearch/detectron
编译python库 cd DETECTRON/lib && make
(DETECTRON表示你clone下来的文件夹) 测试是否编译成功 python2 $DETECTRON/tests/test_spatial_narrow_as_op.py
(DETECTRON表示你clone下来的文件夹)
detectron 使用测试
说明文档:https://github.com/facebookresearch/Detectron/blob/master/GETTING_STARTED.md
根据不同的需求,对象检测可以分为几种,1)Bounding box,2)Mask,3)KeyPoints
这里给出两个例子,用mask和
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-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 \
demo
python2 tools/infer_simple.py \
--cfg configs/12_2017_baselines/e2e_keypoint_rcnn_R-101-FPN_s1x.yaml \
--output-dir /tmp/detectron-visualizations \
--image-ext jpg \
--wts https://s3-us-west-2.amazonaws.com/detectron/37698009/12_2017_baselines/e2e_keypoint_rcnn_R-101-FPN_s1x.yaml.08_45_57.YkrJgP6O/output/train/keypoints_coco_2014_train%3Akeypoints_coco_2014_valminusminival/generalized_rcnn/model_final.pkl \
demo
Reference
https://blog.csdn.net/Yan_Joy/article/details/70241319
https://blog.csdn.net/xiangxianghehe/article/details/70171342