1. 准备 TensorFlow 环境
Tensorflow (>= 1.0.0)
安装对应 python 库:
[cpp] view plain copy
- sudo apt-get install cython python-opencv python-tk python-scipy python-yaml
- sudo pip install easydict
- sudo pip install matplotlib
- sudo python -m pip install Pillow
如果不行就先
- sudo apt-get update
2. Gtihub 代码
代码下载:https://github.com/CharlesShang/TFFRCNN
直接
- git clone https://github.com/CharlesShang/TFFRCNN
3. 下载训练好的网络
在 TFFRCNN-master 下新建文件夹 model,存放要下载入的 net(参考 Github 下载地址),推荐下载:
——.VGG16 - https://drive.google.com/file/d/0B_xFdh9onPagX0JWRlR0cTZ5OGc/view
——.VGG16 - https://drive.google.com/file/d/0B_xFdh9onPagVmt5VHlCU25vUEE/view
——.Resnet50 - https://drive.google.com/file/d/0B_xFdh9onPagbXk1b0FIeDRJaU0/view
百度云链接:
Resnet:https://pan.baidu.com/s/1kWRYN3L 密码:yylr
VGG:https://pan.baidu.com/s/1bpOBguz 密码:8rdu
在faster rcnn根目录下新建一个model文件放进去
4. 编译
打开 lib文件夹下的 make.sh,根据提示修改,如果是 binary版本的 TensorFlow,需要关闭 D_GLIBCXX_USE_CXX11_ABI,设为0:
事先要查看gcc版本(我的是版本五,但是好像是 binary,因此也要注意一下make.sh的语句要改一下,一定要改)
- gcc --version
[cpp] view plain copy
- ## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
- g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o roi_pooling.so roi_pooling_op.cc \
- roi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64
-
- # for gcc5-built tf
- #g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=1 -o roi_pooling.so roi_pooling_op.cc \
- # roi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64
- cd ..
-
-
- # add building psroi_pooling layer
- cd psroi_pooling_layer
- nvcc -std=c++11 -c -o psroi_pooling_op.cu.o psroi_pooling_op_gpu.cu.cc \
- -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52
-
- #g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc \
- # psroi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64
-
- ## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
- g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o psroi_pooling.so psroi_pooling_op.cc \
- psroi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64
执行命令行 make:
[cpp] view plain copy
- cd ./lib
- make # compile cython and roi_pooling_op, you may need to modify make.sh for your platform
5. 运行
将 faster_rcnn/ 文件夹下的 demo.py copy到根目录下,执行如下命令:
[cpp] view plain copy
- cd ..
- python demo.py --model your model path