caffe安装记录
依赖项安装
sudo apt-get update
sudo apt-get install -y --no-install-recommends \ build-essential \ cmake \ git \ libgoogle-glog-dev \ libprotobuf-dev \ protobuf-compiler \ python-dev \ python-pip sudo pip install numpy protobuf
源码下载及安装
git clone --recursive https://github.com/caffe2/caffe2.git && cd caffe2
make && cd build && sudo make install
注意:若在github上用zip格式下载,可能会出现若干第三方包(caffe2/third_party/)下载不下来的错误,因此请使用git clone,即上面的代码进行下载和安装;
测试安装是否成功:
python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
输出success则安装成功
GPU测试:
python -m caffe2.python.operator_test.relu_op_test
成功:
<caffe2.proto.caffe2_pb2.DeviceOption at 0x7ff19b6237d0>], engine=u'CUDNN')
.
----------------------------------------------------------------------
Ran 1 test in 4.858s
OK
错误:Cudnn.h: No such file or directory
报错:
In file included from
/home/hw/main-data/00_softwares/caffe2/caffe2/core/context_gpu.cu:10:0:
/home/hw/main-data/00_softwares/caffe2/caffe2/core/common_cudnn.h:7:19: fatal error: cudnn.h: No such file or directory
原因:cudnn未安装
解决方案:下载:https://developer.nvidia.com/rdp/cudnn-download
cuDNN v7.0 Library for Linux
#解压文件
tar -zxvf cudnn-6.5-linux-x64-v2.tgz
#切换路径
cd cudnn-6.5-linux-x64-v2
#复制lib文件到cuda安装路径下的lib64/
sudo cp lib* /usr/local/cuda/lib64/
#复制头文件
sudo cp cudnn.h /usr/local/cuda/include/
建议:直接切换到su管理员权限,进行复制文件操作;网上说的需要更新软链接,我装的时候没有用上,补充在下边:
更新软连接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.6.5
sudo ln -s libcudnn.so.6.5.48 libcudnn.so.6.5
sudo ln -s libcudnn.so.6.5 libcudnn.so
错误:No module named past.builtins
解决方案: Sudo pip install future
安装不成功,请更换pip源: sudo vim ~/.pip/pip.conf
添加:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
错误:No module named hypothesis
解决方案: sudo pip install hypothesis
错误:在build文件夹下运行示例成功,其他文件夹错误
环境变量未设置好,python运行时不知道搜索路径,请做如下操作
echo $PYTHONPATH
export PYTHONPATH=/usr/local:$PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/home/hw/main-data/00_softwares/caffe2/build
echo $LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
如果还是不行:
vim / etc/bash.bashrc
末尾添加
export PYTHONPATH=/usr/local:$PYTHONPATH
export PYTHONPATH=$PYTHONPATH:/home/hw/main-data/00_softwares/caffe2/build
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH