1、下载源码
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
2、进入目录lib修改setup.py文件,如下
#CUDA = locate_cuda()
#Extension('nms.gpu_nms',
# ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
# library_dirs=[CUDA['lib64']],
# libraries=['cudart'],
# language='c++',
# runtime_library_dirs=[CUDA['lib64']],
# this syntax is specific to this build system
# we're only going to use certain compiler args with nvcc and not with
# gcc the implementation of this trick is in customize_compiler() below
# extra_compile_args={'gcc': ["-Wno-unused-function"],
# 'nvcc': ['-arch=sm_35',
# '--ptxas-options=-v',
# '-c',
# '--compiler-options',
# "'-fPIC'"]},
# include_dirs = [numpy_include, CUDA['include']]
#),
3、执行make
4、进入目录caffe-fast-rcnn
cp Makefile.config.example Makefile.config
修改Makefile.config 文件,注释掉CUDA相关配置
5、执行
make -j8 && make pycaffe
其中缺少很多头文件,自己安装相应的文件就好
cannot find -lhdf5 参考博客
https://blog.csdn.net/object_allen/article/details/73933934
6、还有一些文件修改参考
https://www.cnblogs.com/justinzhang/p/5386837.html
7、测试
在tools目录下执行python demo.py --cpu
Check failed: *ptr host allocation of size 345600000 failed
貌似是内存不足引起!!!
在一篇博客看到,vgg16是大型模型,需要改成ZF小型模型,或者中型模型
执行./demo.py --cpu --net zf 就可以啦!
8、模型训练
(1)注释tools目录下的tools/train_faster_rcnn_alt_opt.py
#parser.add_argument('--gpu', dest='gpu_id',
# help='GPU device id to use [0]',
# default=0, type=int)
# set up caffe
caffe.set_mode_cpu()#改成cpu模式
#caffe.set_device(cfg.GPU_ID)
(2)修改experiments/scripts/faster_rcnn_alt_opt.sh
NET=$1
NET_lc=${NET,,}
DATASET=$2
time ../../tools/train_faster_rcnn_alt_opt.py \
--net_name ${NET} \
--weights data/imagenet_models/${NET}.v2.caffemodel \
--imdb ${TRAIN_IMDB} \
--cfg ../cfgs/faster_rcnn_alt_opt.yml \
${EXTRA_ARGS}
set +x
NET_FINAL=`grep "Final model:" ${LOG} | awk '{print $3}'`
set -x
time ../../tools/test_net.py \
--def models/${PT_DIR}/${NET}/faster_rcnn_alt_opt/faster_rcnn_test.pt \
--net ${NET_FINAL} \
--imdb ${TEST_IMDB} \
--cfg ../cfgs/faster_rcnn_alt_opt.yml \
${EXTRA_ARGS}
(3)执行
./faster_rcnn_alt_opt.sh ZF pascal_voc
error1:可以参考博客1;
I0627 10:57:37.710443 10173 solver.cpp:81] Creating training net from train_net file: models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt
F0627 10:57:37.710464 10173 io.cpp:36] Check failed: fd != -1 (-1 vs. -1) File not found: models/pascal_voc/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt
error2:可以参考博客2;
AttributeError: 'module' object has no attribute 'text_format'
error3:可以参考博客3;
NOT implement!
参考博客1:https://blog.csdn.net/Suii_v5/article/details/73776299
参考博客2:https://blog.csdn.net/qq_33202928/article/details/72526710
参考博客3:https://blog.csdn.net/qq_14975217/article/details/51495844
参考博客4:https://blog.csdn.net/a8039974/article/details/77628805
参考博客5:https://www.cnblogs.com/justinzhang/p/5386837.html
参考博客6:https://blog.csdn.net/object_allen/article/details/73933934
参考博客7:https://blog.csdn.net/Gavin__Zhou/article/details/52052915