论文地址:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
硬件平台:
Ubuntu 18.04(VMware)
Python 3.6
TensorFlow 1.x
原始代码链接:tf-faster-rcnn
参数修改过程如下:
1、config.py文件修改:
# Use GPU implementation of non-maximum suppression
__C.USE_GPU_NMS = False
2、nms_wrapper.py文件修改:(注释掉gpu_nms)
#from nms.gpu_nms import gpu_nms
#if cfg.USE_GPU_NMS and not force_cpu:
#return gpu_nms(dets, thresh, device_id=0)
3、setup.py (注释掉GPU/CUDA部分)
#CUDA = locate_cuda()
...
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
print(extra_postargs)
if os.path.splitext(src)[1] == '.cu':
# use the cuda for .cu files
#self.set_executable('compiler_so', CUDA['nvcc'])
# use only a subset of the extra_postargs, which are 1-1 translated
# from the extra_compile_args in the Extension class
postargs = extra_postargs['nvcc']
else:
postargs = extra_postargs['gcc']
...
#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']]
#)
4、进入lib/Makefile 执行
make
5、data目录下创建coco文件件
cd data
git clone https://github.com/pdollar/coco.git
cd coco/PythonAPI
make
6、下载预训练模型 voc_0712_80k-110k.tgz 百度网盘下载 提取码: 6dz8
NET=res101
TRAIN_IMDB=voc_2007_trainval+voc_2012_trainval
mkdir -p output/${NET}/${TRAIN_IMDB}
cd output/${NET}/${TRAIN_IMDB}
ln -s ../../../voc_2007_trainval+voc_2012_trainval ./default
7、运行demo.py:在data文件下运行:
python3 ../tools/demo.py
8、实验结果:
可以看到,没有GPU加速,识别速度至少在32s以上,识别效果见下图:
practice makes perfect!
参考博客: