caffe配置问题与解决方法集锦

问题1: Check failed: error == cudaSuccess (8 vs. 0) invalid device function

  今天看一篇Paper的时候,要用到Facebook基于caffe改动的适用于3D卷积的代码:C3D: a modified version of BVLC caffe to support 3D ConvNets。于是就git下来,进行配置,Facebook用的caffe是很早之前的caffe了,看源码应该是2014年的。
  在配置时,make all -jmake test -j都通过了,唯独在make runtest -j这里卡住了,把我这个“专业配置caffe50年”的“老手”都难住了。但经过google,还是找到了解决办法。
  我的这个解决办法不一定适用于你的,但如果能帮到你,那真是太好了!^_^…

我的问题如下:

Check failed: error == cudaSuccess (8 vs. 0)  invalid device function

出现问题,Google之,最后问题定位在Makefile.config中的这一部分:

# CUDA architecture setting: going with all of them (up to CUDA 5.5 compatible).
# For the latest architecture, you need to install CUDA >= 6.0 and uncomment
# the *_50 lines below.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
             -gencode arch=compute_20,code=sm_21 \
             -gencode arch=compute_30,code=sm_30 \
             -gencode arch=compute_35,code=sm_35
             #-gencode=arch=compute_50,code=sm_50 \
             #-gencode=arch=compute_50,code=compute_50 \

这是我开始时未改动的Makefile.config中的部分,这种错误的情况是由于显卡计算能力的不同而又没配置好导致的。要将上面的CUDA_ARCH参数改为与你显卡相匹配的数值。
常见的显卡计算能力如下表:

这里写图片描述

我的是 TITAN X计算能力是 5.2,因此,我将上面的 Makefile.config文件中的 CUDA_ARCH参数改为如下:

CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
             #-gencode arch=compute_20,code=sm_21 \
             #-gencode arch=compute_30,code=sm_30 \
             #-gencode arch=compute_35,code=sm_35
             #-gencode=arch=compute_50,code=sm_50 \
             #-gencode=arch=compute_50,code=compute_50 \
             -gencode arch=compute_52,code=compute_52

就是把其余的都注释掉,增加一行自己显卡与之相对应计算能力的设置:

CUDA_ARCH := -gencode arch=compute_52,code=compute_52

再重新编译caffe,再make runtest -j:

这里写图片描述

至于 YOU HAVE 2 DISABLED TESTS参见我这篇博客里,直接忽略掉,不影响。

Reference:
1. http://blog.csdn.net/u013078356/article/details/51009470
2. http://www.cnblogs.com/yymn/articles/5389904.html


问题2 fatal error: pyconfig.h: No such file or directory

紧接着问题1的环境,我在make pycaffe的时候,又报如下错误:

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
compilation terminated.
make: *** [python/caffe/_caffe.so] Error 1

我解决的方法参考自这个网页

这里写图片描述

所以,按照大神的指示,敲:

$ export CPLUS_INCLUDE_PATH=/usr/include/python2.7

搞定~

这里写图片描述

之后, import caffe也能成功import.


问题3 cuDNN 版本问题导致在 make 时在 cudnn_conv_layer 报错

今天在编译fast-rcnn的 caffe 时,报如下错误:

src/caffe/layers/cudnn_conv_layer.cu: error: argument of type cudnnAddMode_t is incompatible with parameter of type const void *
    detected during instantiation of void caffe::CuDNNConvolutionLayer Dtype Forward_gpu(const std vector caffe Blob Dtype *, std allocator caffe Blob Dtype &, const std vector caffe Blob Dtype , std allocator caffe Blob Dtype &) [with Dtype=float]
…………
src/caffe/layers/cudnn_conv_layer.cu: error: argument of type “const void *” is incompatible with parameter of type “cudnnTensorDescriptor_t”
…………
src/caffe/layers/cudnn_conv_layer.cu: error: argument of type “const void *” is incompatible with parameter of type “cudnnTensorDescriptor_t”
…………

20 errors detected in the compilation of “/tmp/tmpxft_000045c5_00000000-16_cudnn_conv_layer.compute_50.cpp1.ii”.

make: * [.build_debug/cuda/src/caffe/layers/cudnn_conv_layer.o] Error 1
make: * Waiting for unfinished jobs….

截图如下:

这里写图片描述

这种情况一般是 cuDNN 版本链接问题导致的,要么升级 cuDNN 的版本,要么将 cuDNN 的版本进行降级。这里,我一般要么是将 cnDNN v2 升级到 cuDNN v4,要么将 cuDNN v4 降级到 cuDNN v2,。虽说现在 cuDNN 的版本已经到 v5 了,但目前我刚刚说的两种思路都能解决我遇到的问题。
之后, fast-rcnn编译成功。


问题4 caffe/ proto/ caffe.pb.h: No such file or directory

这个问题,也是我在编译 fast-rcnn时遇到的:

In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer_factory.cpp:3:

./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: No such file or directory

compilation terminated.

这里写图片描述

这个问题的解决办法参考这个博客:http://blog.csdn.net/xmzwlw/article/details/48270225

用protoc从caffe/src/caffe/proto/caffe.proto生成caffe.pb.h和caffe.pb.cc

$ protoc --cpp_out=/home/chenxp/caffe/include/caffe/ caffe.proto 

这里写图片描述

这个解决办法几乎百试百灵。


问题5 syncedmem.hpp: 18 Check failed: error == cudaSuccess (30 vs. 0)

2016.06.28 更新

今天倩姐说她的torch跑不起来,我看了一下,可能是CUDA出问题了。我又将服务器上的caffe重新编译,果然不出所料,遇到的如下问题:

F0628 15:34:16.652927 50205 syncedmem.hpp:18] Check failed: error == cudaSuccess (30 vs. 0) unknown error
* Check failure stack trace: *
@ 0x2ab5de98fdaa (unknown)
@ 0x2ab5de98fce4 (unknown)
@ 0x2ab5de98f6e6 (unknown)
@ 0x2ab5de992687 (unknown)
@ 0x2ab5e0959ef9 caffe::SyncedMemory::mutable_cpu_data()
@ 0x2ab5e0957618 caffe::Blob<>::Reshape()
@ 0x2ab5e0957c7a caffe::Blob<>::Reshape()
@ 0x57643c caffe::MemoryDataLayerTest<>::SetUp()
@ 0x8fa70a testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x8efd71 testing::Test::Run()
@ 0x8efec7 testing::TestInfo::Run()
@ 0x8f0005 testing::TestCase::Run()
@ 0x8f027d testing::internal::UnitTestImpl::RunAllTests()
@ 0x8fa28a testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x8ef641 testing::UnitTest::Run()
@ 0x46d027 main
@ 0x2ab5e1933f45 (unknown)
@ 0x4748e9 (unknown)
@ (nil) (unknown)
make: * [runtest] Aborted (core dumped)

这里写图片描述

我在这里找到了答案,安装个东西就可以了:sudo apt-get install nvidia-modprobe

这里写图片描述

之后,再make runtest -j,搞定!


问题6 undefined reference to imdecode( )

今天给吉姐编译 Caffe 的时候,碰到如下的错误:

.build_release/lib/libcaffe.so: undefined reference to cv::imdecode(cv::_InputArray const&, int)
.build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)

这里写图片描述

因为昨天我将在服务器上编译安装了 openCV3,所以我怀疑是 openCV 的问题。
想起来 Caffe 的 Makefile.config 中,有一个注释,当我们使用 openCV3 的时候,需要取消。果然,当取消之后,就可以 make all 了。


问题7 libopencv_core.so.3.1: connot open shared object file: No such file or directory

但是随后又碰到了一个问题,是在 make runtest -j 的时候,报如下错误:

Error while loading libraries: libopencv_core.so.3.1: connot open shared object file: No such file or directory

这里写图片描述

Google 之,参考如下两个,找到解决办法:
1. https://github.com/BVLC/caffe/issues/3700
2. http://www.cnphp6.com/archives/141601

报这个错误是因为找不到 openCV3 的库,可以使用下面方式导入:

export LD_LIBRARY_PATH =/usr/local/lib:$LD_LIBRARY_PATH

make runtest -j 的时候,就全部成功了。

  • 3
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
要在Windows上配置Caffe,首先需要确保已经安装了所需的软件和工具。以下是详细的步骤: 1. 安装CUDA和CUDNN:Caffe在GPU上进行加速需要CUDA和CUDNN的支持。首先,下载并安装适合你的显卡型号的CUDA驱动程序。然后,从NVIDIA的官方网站下载并安装CUDNN库。 2. 安装依赖库:在Windows上运行Caffe还需要一些依赖库。你可以使用包管理工具(如Chocolatey)快速安装这些库。运行命令`choco install git python2`来安装Git和Python。 3. 克隆Caffe:打开命令提示符,导航到你想要存储Caffe的目录,并使用以下命令克隆Caffe的代码库:`git clone https://github.com/BVLC/caffe.git` 4. 配置环境:进入Caffe目录,在根目录下创建一个新的文件夹"build",用于存储编译后的文件。然后,将模板文件夹"windows"复制到"build"文件夹内。重命名此文件夹为"CMake"。 5. 使用CMake配置:打开CMake GUI,选择"Caffe"文件夹作为源代码目录,选择"build"文件夹作为目标目录。点击"Configure"按钮选择你安装的编译器和生成器(如Visual Studio)。然后点击"Generate"生成解决方案。 6. 编译Caffe:打开生成的解决方案,选择合适的编译选项(如Release、Debug等),然后开始编译。这可能需要一些时间,取决于你的电脑配置和编译选项。 7. 配置环境变量:将Caffe的"build\bin"路径添加到系统的环境变量中,这样才能在命令提示符或其他地方运行Caffe命令。 现在,你已经成功在Windows上配置Caffe,可以使用它进行深度学习任务了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值