tf-faster-rcnn Ubuntu 14.0 CPU环境下调试记录

 

参考 https://github.com/endernewton/tf-faster-rcnn中的readme。

1.克隆源码

 git clone https://github.com/endernewton/tf-faster-rcnn.git

2.修改配置文件使用CPU

        因为使用的是CPU,根据readme中提示,需要 set USE_GPU_NMS False。所以编辑配置文件:

cd tf-faster-rcnn/lib
vim model/config.py

        大概在270行修改:

# Use GPU implementation of non-maximum suppression
#__C.USE_GPU_NMS = True
__C.USE_GPU_NMS = False

        Build the Cython modules:

        readme中这么操作:

make clean
make
cd ..

很不幸,make之后报错:

python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 55, in <module>
    CUDA = locate_cuda()
  File "setup.py", line 43, in locate_cuda
    raise EnvironmentError('The nvcc binary could not be '
EnvironmentError: The nvcc binary could not be located in your $PATH. Either add it to your path, or set $CUDAHOME
make: *** [all] 错误 1

         提示没有nvcc,于是寻找解决办法,这里参考:https://blog.csdn.net/sinat_33486980/article/details/81045315。主要是去掉查找cuda部分代码和编译用到的cuda相关的库。

setup.py 55行注释掉:

#CUDA = locate_cuda()

120-136行注释掉:

ext_modules = [
    Extension(
        "utils.cython_bbox",
        ["utils/bbox.pyx"],
        extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
        include_dirs = [numpy_include]
    ),
    Extension(
        "nms.cpu_nms",
        ["nms/cpu_nms.pyx"],
        extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
        include_dirs = [numpy_include]
    ),
    #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']]
    #)
]

然后 make,无错误。再cd ..。

3.安装Python COCO API,访问COCO数据集需要

        按照readme步骤:

cd data
git clone https://github.com/pdollar/coco.git
cd coco/PythonAPI
make
cd ../../..

很不幸,又报错了:

python setup.py build_ext --inplace
running build_ext
building 'pycocotools._mask' extension
error: unknown file type '.pyx' (from 'pycocotools/_mask.pyx')
make: *** [all] 错误 1

参考:https://blog.csdn.net/weixin_41813620/article/details/85590891,下载Pyrex并安装,其官网:http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/,其安装:

wget http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/Pyrex-0.9.9.tar.gz
tar -zxvf Pyrex-0.9.9.tar.gz
cd Pyrex-0.9.9
python setup.py install

再去make Python COCO API,还是报错:

python setup.py build_ext --inplace
running build_ext
pyrexc pycocotools/_mask.pyx --> pycocotools/_mask.c
/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/data/coco/PythonAPI/pycocotools/_mask.pyx:42:34: Expected ')'
building 'pycocotools._mask' extension
creating build
creating build/common
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/pycocotools
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I../common -I/usr/include/python2.7 -c ../common/maskApi.c -o build/temp.linux-x86_64-2.7/../common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99
../common/maskApi.c: In function ‘rleToBbox’:
../common/maskApi.c:141:31: warning: ‘xp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       if(j%2==0) xp=x; else if(xp<x) { ys=0; ye=h-1; }
                               ^
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I../common -I/usr/include/python2.7 -c pycocotools/_mask.c -o build/temp.linux-x86_64-2.7/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
x86_64-linux-gnu-gcc: error: pycocotools/_mask.c: 没有那个文件或目录
x86_64-linux-gnu-gcc: fatal error: no input files
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 4
make: *** [all] 错误 1

提示没有_mask.c,参考https://blog.csdn.net/weixin_41813620/article/details/85590891,手动生成这个文件:

cd pycocotools
cython _mask.pyx
cd ..

再make,无报错。

4.Demo

下载预训练模型:

./data/scripts/fetch_faster_rcnn_models.sh

报错:

Downloading Resnet 101 Faster R-CNN models Pret-trained on VOC 07+12 (340M)...
--2019-03-01 05:31:53--  http://ladoga.graphics.cs.cmu.edu/xinleic/tf-faster-rcnn/res101/voc_0712_80k-110k.tgz
正在解析主机 ladoga.graphics.cs.cmu.edu (ladoga.graphics.cs.cmu.edu)... 128.2.220.68
正在连接 ladoga.graphics.cs.cmu.edu (ladoga.graphics.cs.cmu.edu)|128.2.220.68|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 读取文件头错误 (连接被对方重设)。
重试中。

打开这个文件看下,发现作者已经提示,网址连接不上换一下,于是重新换一下URL:

vim data/scripts/fetch_faster_rcnn_models.sh

第九行:

# replace it with gs11655.sp.cs.cmu.edu if ladoga.graphics.cs.cmu.edu does not work
#URL=http://ladoga.graphics.cs.cmu.edu/xinleic/tf-faster-rcnn/$NET/$FILE
URL=http://gs11655.sp.cs.cmu.edu/xinleic/tf-faster-rcnn/$NET/$FILE

重新运行脚本,好吧,根本不行:

Downloading Resnet 101 Faster R-CNN models Pret-trained on VOC 07+12 (340M)...
--2019-03-01 05:37:41--  http://gs11655.sp.cs.cmu.edu/xinleic/tf-faster-rcnn/res101/voc_0712_80k-110k.tgz
正在解析主机 gs11655.sp.cs.cmu.edu (gs11655.sp.cs.cmu.edu)... 失败:未知的名称或服务。
wget: 无法解析主机地址 “gs11655.sp.cs.cmu.edu”
Unzipping...

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Done. Please run this command again to verify that checksum = cb32e9df553153d311cc5095b2f8c340.

参考:https://blog.csdn.net/weixin_41813620/article/details/85590891,到百度网盘下载:https://pan.baidu.com/s/1kWkF3fT。下载之后,把它放到tf-faster-rcnn/data下,然后解压:

tar zxvf data/voc_0712_80k-110k.tgz

创建一个文件夹和一个软连接来使用模型

NET=res101
TRAIN_IMDB=voc_2007_trainval+voc_2012_trainval
mkdir -p output/${NET}/${TRAIN_IMDB}
cd output/${NET}/${TRAIN_IMDB}
ln -s ../../../data/voc_2007_trainval+voc_2012_trainval ./default
cd ../../..

这里基本没什么问题。

运行Demo:

./tools/demo.py

报错:

Traceback (most recent call last):
  File "./tools/demo.py", line 19, in <module>
    from model.config import cfg
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/__init__.py", line 1, in <module>
    from . import config
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/config.py", line 9, in <module>
    from easydict import EasyDict as edict
ImportError: No module named easydict

这个比较简单,安装easydict就行:

pip install easydict

然后./tools/demo.py,还是报错:

Traceback (most recent call last):
  File "./tools/demo.py", line 20, in <module>
    from model.test import im_detect
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/test.py", line 24, in <module>
    from model.nms_wrapper import nms
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/nms_wrapper.py", line 12, in <module>
    from nms.gpu_nms import gpu_nms
ImportError: No module named gpu_nms

因为没有gpu,要把lib/model/nms_wrapper.py的12行注释掉,再运行。

Traceback (most recent call last):
  File "./tools/demo.py", line 25, in <module>
    import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot

额,没装matplotlib,于是又安装matplotlib:

pip install matplotlib

结果还在安装过程报错:

Downloading/unpacking matplotlib
  Downloading matplotlib-3.0.3.tar.gz (36.6MB): 36.6MB downloaded
  Running setup.py (path:/tmp/pip_build_root/matplotlib/setup.py) egg_info for package matplotlib
    
    Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.
    Beginning with Matplotlib 3.0, Python 3.5 and above is required.
    
    This may be due to an out of date pip.
    
    Make sure you have pip >= 9.0.1.
    
    Complete output from command python setup.py egg_info:
    

Matplotlib 3.0+ does not support Python 2.x, 3.0, 3.1, 3.2, 3.3, or 3.4.

Beginning with Matplotlib 3.0, Python 3.5 and above is required.



This may be due to an out of date pip.



Make sure you have pip >= 9.0.1.



----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/matplotlib
Storing debug log for failure in /home/kmin/.pip/pip.log

按照提示,要更新pip,于是更新:

sudo pip install --upgrade pip

再安装matplotlib,成功装上。再运行./tools/demo.py:

Traceback (most recent call last):
  File "./tools/demo.py", line 30, in <module>
    from nets.vgg16 import vgg16
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/nets/vgg16.py", line 11, in <module>
    import tensorflow.contrib.slim as slim
ImportError: No module named contrib.slim

更新下tensorflow:

pip install --upgrade tensorflow

再运行,报错:

Traceback (most recent call last):
  File "./tools/demo.py", line 20, in <module>
    from model.test import im_detect
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/test.py", line 23, in <module>
    from model.bbox_transform import clip_boxes, bbox_transform_inv
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/bbox_transform.py", line 12, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: No module named protobuf

下载protobuf,下载地址:https://github.com/protocolbuffers/protobuf/releases/tag/v3.7.0。然后解压,进入解压的文件夹,里面有个python文件夹,进入,然后:

python setup.py build
python setup.py install

再运行,报错:

Traceback (most recent call last):
  File "./tools/demo.py", line 20, in <module>
    from model.test import im_detect
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/test.py", line 23, in <module>
    from model.bbox_transform import clip_boxes, bbox_transform_inv
  File "/home/kmin/tianchi/jinjin/faster-rcnn/tf-faster-rcnn/tools/../lib/model/bbox_transform.py", line 12, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 122, in <module>
    from tensorflow.python.platform import test
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/test.py", line 30, in <module>
    from tensorflow.python.framework import test_util as _test_util
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/test_util.py", line 73, in <module>
    from tensorflow.python.platform import googletest
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/googletest.py", line 35, in <module>
    from tensorflow.python.platform import benchmark
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 122, in <module>
    class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
  File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass
    return meta("NewBase", bases, {})
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/benchmark.py", line 117, in __new__
    if not newclass.is_abstract():
AttributeError: type object 'NewBase' has no attribute 'is_abstract'

更新six可以解决:

sudo easy_install --upgrade six

终于,可以运行了:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值