因为github上开源的代码都是两三年前的,所以我们复现起来会遇到各种各样奇怪的问题。
在我查阅了很多的CSDN博客和github上的问题后终于解决了问题
代码实现过程如下(我是按照我自己遇到的问题来写的,仅供参考)
https://github.com/endernewton/tf-faster-rcnn
在集群(centos)上用anaconda配置的环境,
所需要的环境有:python2.7,tensorflow-gup=1.6,cython,opencv-python, matplotlib,easydict=1.6,cuda, cudnn(注意这个是7.1.2版本的)此处不仔细讲了,github上和其他博客上讲的很详细。
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
解压后直接把VOCdevkit文件夹拷贝到tf-fater-rcnn/data路径下,并重命名为VOCdevkit2007
预训练的模型:https://pan.baidu.com/s/1F8VfDKjlq9x42ZDrrvfx2A 密码:8ahl
COCOAPI:https://github.com/cocodataset/cocoapi
最后把VOCdevkit、coco、voc_2007_trainval+voc_2012_trainval都放在data文件夹下
简述我更改的地方,以供大家参考:
1.tf-faster-rcnn-master\lib\setup.py
# 注释掉这几段代码
# CUDA = locate_cuda()
# self.set_executable('compiler_so', CUDA['nvcc'])
# 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_52',
# '--ptxas-options=-v',
# '-c',
# '--compiler-options',
# "'-fPIC'"]},
# include_dirs = [numpy_include, CUDA['include']]
# )
2.tf-faster-rcnn-master\lib\model\config.py
# 把原来的True改为False
# Use GPU implementation of non-maximum suppression
__C.USE_GPU_NMS = False
3.tf-faster-rcnn-master\lib\model\nms_wrapper.py
# 注释掉这段代码
# from nms.gpu_nms import gpu_nms
4.tf-faster-rcnn-master\tools\demo.py
# 添加这几段代码(注意import matplotlib.pyplot as plt要放到最后)
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# 把最后的 plt.show()注释掉改为plt.savefig
plt.savefig("pic.png")
# plt.show()
5.cudnn的版本不匹配问题:
参考:https://blog.csdn.net/htt789/article/details/79627015
最后运行:
GPU_ID=0
CUDA_VISIBLE_DEVICES=${GPU_ID} python ./tools/demo.py
在tf-faster-rcnn-master的目录下就可以看到pic.png图片