caffe2环境配置之一二

本文详细介绍了在Centos7环境下,针对无sudo权限用户及内网环境如何配置caffe2环境,包括下载安装、验证步骤、解决protobuf版本问题、cmake注意事项、Python包版本冲突等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

caffe2环境配置之一二

环境 : Centos 7 + cuda-8.0 + cudnn-v6.0 + python2.7 + caffe2
该方法适应于权限有限的用户(无sudo权限)(不能在/usr/local生成protobuf等自编译文件
以及处于公司内网不能访问外网情况

1 下载并编译安装

1.1下载caffe2以及第三方库

对于处于内网环境来说,一定要在外网把第三方库都下完全了,

git clone --recursive https://github.com/caffe2/caffe2.git

git源代码时要记得加上–recursive,便会自动递归更新子模块

1.2 编译安装
cd ROOT_CAFFE2
mkdir build && cd build
cmake ..
make -j8 install

当需要指定安装目录时,可以将 make -j8 install 改为 export DESTDIR="$HOME" && make -j8 install, 然后配置环境

export PATH="/home/XX/usr/local/caffe2:$PATH"
export PYTHONPATH=/home/XX/usr/local:$PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/home/XX/caffe2/build
export LD_LIBRARY_PATH=/home/XX/usr/local/lib:$LD_LIBRARY_PATH
1.3 验证是否安装成功
python -c'from caffe2.python import core'2>/dev/null && echo"Success" || echo"Failure"

2 protobuf

protobuf版本不对会带来各种问题,比如

2.1 问题来源1:

.build_release/lib/libcaffe.so: undefined reference to google ::protobuf…
此时你的protobuf库与链接库已经混乱了

2.2 问题来源2:

*pb.h:9:42:fatal error:google/protobuf/stubs/common.h:No such file or directory
看看这个你应该知道,找不到头文件,没有链接上去:
来自stackoverflow.解决方案:
g++ -I/path/to/protobuf/include -c my-source.cc
./configure CXXFLAGS=-I/path/to/protobuf/include
sudo apt-get install libprotobuf-dev protobuf-compiler

亲测有效解决方案:在.bashrc添加protobuf为c,c++链接库
export OBJC_INCLUDE_PATH=$PROTOBUF_CAFFE
export C_INCLUDE_PATH=$PROTOBUF_CAFFE
export CPLUS_INCLUDE_PATH=$PROTOBUF_CAFFE

其中,PROTOBUF_CAFFE=ROOT_CAFFE2/third_party/protobuf/src,为下载的第三方库中protobuf源码

2.3问题来源3

“cannot import name descriptor_pb2”
TypeError: __init__() got an unexpected keyword argument 'file'
解决方案:将anaconda下的google下的protobuf更新即可

终极解决方案: 将各种冲突protobuf源屏蔽,比如Anoconda以及tensorflow中等,在编译安装过程最好通过直接更改.bashrc文件关掉其它版本的protobuf,安装完成后再重新打开个各版本protobuf即可

3 cmake时注意事项

因caffe2在cmake时会寻找/usr/local/下面的库,故若无权限在/usr/local/时便会出现一些问题,其中有关protobuf出现问题最多
USE_NCCL
USE_LITE_PROTO
BUILD_CUSTOM_PROTOBUF
这几个开关根据情况而定,如若cmake出错,将相应的开关关闭即可,例如将1.2中的cmake ..更改为
cmake -DUSE_NCCL=OFF -DUSE_LITE_PROTO=ON -DBUILD_CUSTOM_PROTOBUF=ON ..

4 python 包与caffe2版本问题

4.1 - ImportError: No module named past.builtins

缺少future模块
解决方案:sudo pip install future 对于内网来说,先从外网下载好相应的python future安装包,再在内网安装即可

4.2RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9

numpy版本不匹配
可以找到相应的numpy版本替换,可参考方案来更新,博主直接重新更新了Anaconda为最新版本解决了问题

5 gcc g++ 版本问题(4.85以上)

caffe2::CUDAContext::~CUDAContext()': reshape_op_gpu_test.cc:(.text._ZN6caffe211CUDAContextD2Ev[_ZN6caffe211CUDAContextD5Ev]+0x420): undefined reference toTLS init function for caffe2::CUDAContext::cuda_objects_'
libCaffe2_GPU.so: undefined reference to `TLS init function for caffe2::CuDNNWrapper::tls_cudnn_handles_'
collect2: error: ld returned 1 exit status
make[3]: *** [caffe2/binaries/reshape_op_gpu_test] Error 1

解决方案:gcc,g++版本要大于等于4.85

References:

1.https://www.cnblogs.com/fanninnypeom/p/5982719.html
2.https://blog.youkuaiyun.com/zziahgf/article/details/72461175
3.http://www.cnblogs.com/yiruparadise/p/5671771.html
4.https://segmentfault.com/a/1190000014500134?utm_source=index-hottest
6.https://blog.youkuaiyun.com/zhw864680355/article/details/79602453
7.https://github.com/caffe2/caffe2/issues/1297

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值