使用Nsight Eclipse调试py-faster-rcnn(C++/python混合代码调试)

eclipse版本下载地址:

https://www.eclipse.org/downloads/packages/release

参考:

https://blog.csdn.net/u012177034/article/details/52983672

https://www.jianshu.com/p/6a9ef72dac09

https://www.jianshu.com/p/a67532085ffb

Error in final launch sequence
Failed to execute MI command:
source .cuda-gdbinit
Error message from debugger back end:
.cuda-gdbinit: 没有那个文件或目录.
.cuda-gdbinit: 没有那个文件或目录.

https://stackoverflow.com/questions/14108900/nsight-eclipse-cuda-gdbinit-no-such-file-or-directory

https://stackoverflow.com/questions/13068810/eclipse-debug-error-in-final-sequence-failed-to-execute-mi-command

Eclipse4.2下载地址:

https://archive.eclipse.org/eclipse/downloads/

我选的4.2.2

py-faster-rcnn下载地址:

https://github.com/rbgirshick/py-faster-rcnn

后来发现,需要的不是这个

是这个:

https://developer.nvidia.com/nsight-eclipse-edition

因为我已经安装了显卡驱动和CUDA8.0-and-cuDnn5.1

Pydev安装

根据Eclipse和JDK版本,选择安装Pydev 4.5.0 
强调:Pydev 2.8.2版本最高版本只支持 Eclipse 3.x,最高版本Pydev 5.3.0要求Eclipse最低版本为Eclipse 4.6,因此均能用,使用版本不一致的Pydev会导致安装后Eclipse环境里不出现Pydev选项。Pydev 4.5.0.经验证可使用 

http://www.pydev.org/update_sites/4.5.0/ 

 

因为pydev的更新,原来的网址不管用了,

sudo cp -r plugins/. /usr/local/cuda/libnsight/plugins 
sudo cp -r features/. /usr/local/cuda/libnsight/features/

安装py-faster-rcnn

https://blog.csdn.net/zhaoluruoyan89/article/details/79082427

下载faster-rcnn,l利用下面的命令。(一定要用下面的命令,这样下载的版本才是正确的)
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
如果你下载的版本对的话,home路径下py-faster-rcnn,路径下应该有。caffe-faster-rcnn这个文件。

如果下载不下来,尝试把梯子关闭

https://blog.csdn.net/hzwwpgmwy/article/details/79043251

git clone速度太慢解决方案 

Faster R-CNN 并不支持CUDNN5.1 所以需要合并Caffe来支持

方法1:

  1. cd caffe-fast-rcnn

  2. git remote add caffe https://github.com/BVLC/caffe.git

  3. git fetch caffe

  4. git merge -X theirs caffe/master

  5. (git checkout -f )

  6. (git pull)

或者

Faster R-CNN 并不支持CUDNN5.1 所以需要合并Caffe来支持

方法2:纯手工修改
用最新caffe源码的以下文件替换掉faster rcnn 的对应文件
include/caffe/layers/cudnn_relu_layer.hpp, src/caffe/layers/cudnn_relu_layer.cpp, src/caffe/layers/cudnn_relu_layer.cu

include/caffe/layers/cudnn_sigmoid_layer.hpp, src/caffe/layers/cudnn_sigmoid_layer.cpp, src/caffe/layers/cudnn_sigmoid_layer.cu

include/caffe/layers/cudnn_tanh_layer.hpp, src/caffe/layers/cudnn_tanh_layer.cpp, src/caffe/layers/cudnn_tanh_layer.cu

用caffe源码中的这个文件替换掉faster rcnn 对应文件
include/caffe/util/cudnn.hpp

将 faster rcnn 中的 src/caffe/layers/cudnn_conv_layer.cu 文件中的所有
cudnnConvolutionBackwardData_v3 函数名替换为 cudnnConvolutionBackwardData
cudnnConvolutionBackwardFilter_v3函数名替换为 cudnnConvolutionBackwardFilter 

USE_CUDNN := 1
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include  /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
# Automatic dependency generation (nvcc is handled separately)
CXXFLAGS += -MMD -MP
CXXFLAGS += -std=c++11

# Complete build flags.
#NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
Makefile181行:

caffe-SSD:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_regex m hdf5_hl hdf5

faster-rcnn:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

决定先不改动
cd $FRCN_ROOT/lib (或者cd py-faster-rcnn/lib)
make
make -j8
make pycaffe
sudo gedit ~/.bashrc

export PYTHONPATH=/home/boyun/ynh/code/new_faster_rcnn/caffe-fast-rcnn/python:$PYTHONPATH

source ~/.bashrc

重启
查看环境变量设置是否成功:

echo $PYTHONPATH

echo $PATH
~/ynh/code/new_faster_rcnn/tools$ ./demo.py

新建C++ makefile工程:caffe-fast-rcnn

(1) file->new->makefile project with existing files

(2)新建三个如下图所示的make target

 

选择debug configuration

选中第一个C/C++ Application可以创建第一个

此时就可以对单独的LENET网络的训练进行调试了

选中第二个C/C++ Attach to Application可以创建第二个

作为与py-faster-rcnn工程联合调试时使用,也是本文所要介绍的一个。其类型为’C/C++ Attach to Application’,要调试的文件主要为’python/caffe/_caffe.so’,该文件也是最终要引入python里的caffe库里的最主要的函数来源(其余的均为python源文件)。

需要注意的是Nsight的默认调试器为cuda-gdb,这里需要将其换为gdb(点击图下方的’select other’),如下图。不换的话会出现’coalescing of the cuda commands outputs is off’的问题

 

我的电脑安装了caffe-SSD,可能识别是SSD没关系,先加载上,再删除

先应用,后OK

新建一个py-faster-rcnn,路径选择电脑上之前有的py-faster-rcnn

Eclipse把鼠标移动想要设置断点的行,在行号前面空白地方双击,就会出现断点

然后打开tools._init_paths

修改这一块,改成绝对路径

# Add caffe to PYTHONPATH
#caffe_path = osp.join(this_dir, 'caffe-fast-rcnn', 'python')
caffe_path = '/home/boyun/ynh/code/py-faster-rcnn/tools/caffe-fast-rcnn/python'
add_path(caffe_path)

# Add lib to PYTHONPATH
#lib_path = osp.join(this_dir, '..', 'lib')
lib_path = '/home/boyun/ynh/code/new_faster_rcnn/lib'
add_path(lib_path)

然后打开tools.demo,改成绝对路径

if __name__ == '__main__':
    cfg.TEST.HAS_RPN = True  # Use RPN for proposals

    prototxt = '/home/boyun/ynh/code/new_faster_rcnn/models/pascal_voc/VGG16/faster_rcnn_end2end/test.prototxt'
    #/home/boyun/ynh/code/new_faster_rcnn/models/pascal_voc/VGG16/faster_rcnn_end2end
    caffemodel ='/home/boyun/ynh/code/new_faster_rcnn/models/pascal_voc/VGG16/faster_rcnn_end2end/VGG16_faster_rcnn_final.caffemodel'

    if not os.path.isfile(caffemodel):
        raise IOError(('{:s} not found.\nDid you run ./data/script/'
                       'fetch_faster_rcnn_models.sh?').format(caffemodel))
    caffe.set_device(0)
    caffe.set_mode_gpu()

    cfg.GPU_ID = 0
    net = caffe.Net(prototxt, caffemodel, caffe.TEST)

    print '\n\nLoaded network {:s}'.format(caffemodel)

    # Warmup on a dummy image
    im = 128 * np.ones((300, 500, 3), dtype=np.uint8)
    for i in xrange(2):
        _, _= im_detect(net, im)

    im_names = ['000456.jpg', '000542.jpg', '001150.jpg',
                '001763.jpg', '004545.jpg']
    for im_name in im_names:
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print 'Demo for data/demo/{}'.format(im_name)
        demo(net, im_name)

    plt.show()

 debug 运行,但是出错

warning: Debugger speedups using cython not found. Run "python /home/boyun/.eclipse/org.eclipse.platform_4.4.1_2069420271_linux_gtk_x86_64/configuration/org.eclipse.osgi/343/0/.cp/pysrc/setup_cython.py build_ext --inplace" to build.
pydev debugger: starting (pid: 4786)
Traceback (most recent call last):
  File "/home/boyun/.eclipse/org.eclipse.platform_4.4.1_2069420271_linux_gtk_x86_64/configuration/org.eclipse.osgi/343/0/.cp/pysrc/pydevd.py", line 1520, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/boyun/.eclipse/org.eclipse.platform_4.4.1_2069420271_linux_gtk_x86_64/configuration/org.eclipse.osgi/343/0/.cp/pysrc/pydevd.py", line 927, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/boyun/ynh/code/py-faster-rcnn/tools/demo.py", line 18, in <module>
    from fast_rcnn.test import im_detect
  File "/home/boyun/ynh/code/new_faster_rcnn/lib/fast_rcnn/test.py", line 16, in <module>
    import caffe
  File "/home/boyun/ynh/code/py-faster-rcnn/caffe-fast-rcnn/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/boyun/ynh/code/py-faster-rcnn/caffe-fast-rcnn/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: No module named _caffe

make distribute

这个试了也没啥用 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值