成功安装ubuntu16.04+cuda9.0+cuDNN7.0.5+caffe+digits(附错误汇总)
2017-12-26 16:00
1081 查看
成功安装ubuntu16.04+cuda9.0+cuDNN7.0.5+caffe+digits(附错误汇总)
本机硬件:双核i7 内存8G 显卡GTX070(不好意思,比较水)安装顺序:依赖包-->驱动-->cuda-->cudnn-->caffe --> digits-->测试
时间:2017-12-26
转载请注明出处: http://note.youdao.com/noteshare?id=fb9c38bd268d5bf353c38a89f546e6d7(我的云笔记) http://blog.csdn.net/linyu2016/article/details/78903243 (我的csdn)
欢迎交流,请多多指教~
前言:
有的显卡计算能力不够,例如GTX540的计算能力只有2.1, 而cudnn要求的显卡的计算能力至少是3.0以上,也就是至少GTX830,在此处可以查询计算能力。
cuda9.1与cudnn7是最新款的,但是在caffe编译的时候会出现问题,在make runtest 的时候不通过,所以不建议同时使用。
我的用户名是ly,所以要注意有的路径需要自己根据自己电脑的用户名来改。
1、安装依赖
sudo apt-get install python-pip
sudo pip install easydict protobuf pydot
sudo apt-get install graphviz libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libopenblas-dev liblapack-dev libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-dev python-tk python-numpy python-scipy python-matplotlib
python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags
sudo apt-get install --no-install-recommends libboost-all-dev
2、安装显卡驱动
方法1:
在“软件与更新”的“附加驱动”里查看,查看驱动版本:
执行以下指令安装驱动:
sudo add-apt-repository ppa:xorg-edgers/ppa
sudo apt-get update
sudo apt-get install nvidia-375 或者是(384) #注意在这里指定自己的驱动版本!
重启
方法2:
在“软件与更新”的第二项(另外源)的 canonical partners 打上沟,或者全部都打钩(保险起见)
在倒数第二项的 “附加驱动”里,系统会自动搜索N卡驱动,选择优先级高的英伟达驱动安装,重启
注意:
一般需要重启才能检测到安装成功
sudo nvidia-smi
若列出了GPU的信息列表则表示驱动安装成功。
3、安装CUDA
下载CUDA
方法1:
从此处,下载对应版本的cuda安装包,
我下载的是deb( local) 版。
这种方法是下载最新的cuda,不一定适合显卡低级的电脑。
方法2:
从此处可以下载各个历史版本的cuda,总有一款适合你的显卡,推荐使用此方法。
安装CUDA, 运行如下命令, 即可安装CUDA;
sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb (具体看实际的包)
sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub(若cuda<9.0的,就不用,具体在下载的网页有提示)
sudo apt-get update
sudo apt-get install cuda
安装完成后, 重启一下;
4、安装cuDNN (计算能力小于3.0的,不兼容cudnn的英伟达显卡不需要装cudnn,则忽略此步骤)
从此处下载cuDNN 。注册,然后下载,(注册邮箱最好是使用国外邮箱[Goog
4000
le, apple], 验证邮件很快就能收到),选择对应版本,可以与cuda相同的版本,或者比它小的版本。
切换到cudnn所在的目录下
sudo tar -zxvf cudnn-9.0-linux-x64-v4.0-prod.tgz (具体看实际的包)
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
cd /usr/local/cuda/lib64/
ls
sudo chmod +r libcudnn.so.7.0.5(具体的版本要自己查)
sudo rm -rf libcudnn.so libcudnn.so.7 #删除原有动态文件
sudo ln -s libcudnn.so.7.0.5 libcudnn.so.7 #生成软衔接(注意这里要和自己下载的cudnn版本对应,可以在/usr/local/cuda/lib64下查看自己libcudnn的版本)
sudo ln -s libcudnn.so.7 libcudnn.so #生成软链接
sudo ldconfig -v
5、设置环境变量,
在/etc/profile中添加CUDA环境变量
sudo gedit /etc/profile
在打开的文件最后加入如下3句话
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export PYTHONPATH=/home/用户名/caffe/python:$PYTHONPATH (具体注意用户名)
保存后, 使环境变量立即生效,
source /etc/profile
sudo gedit ~/.bashrc
在打开的文件最后加入如下3句话
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}(具体要注意cuda的版本号)
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}(具体要注意cuda的版本号)
export PYTHONPATH=/home/用户名/caffe/python:$PYTHONPATH
source ~/.bashrc
进入/usr/local/cuda/samples, 执行下面的命令来build samples,
cd /usr/local/cuda/samples
sudo make all -j16(如果电脑CPU比较低,则用-j16或者不加)
全部编译完成后, 进入
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery(具体要注意cuda的版本号)
sudo ./deviceQuery
如果出现显卡信息,结果为pass, 则驱动及显卡安装成功。
6、配置caffe
(1)下载caffe(也可以复制源代码到用户名文件夹下)
cd
sudo git clone https://github.com/BVLC/caffe.git
网速如果比较慢的话,可用ctrl+c结束进程。再次输入语句,重新开始下载。
(2)配置caffe文件 修改caffe/Makefile.config,
cd /home/用户名/caffe(具体路径自己改)
sudo cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
USE_CUDNN := 1#去掉这个注释,因为要使用cudnn(但是假如显卡太低级,兼容性不够,就用不了cudnn)
# CPU_ONLY := 1#加上这个注释(因为要使用cuda,所以就不用改)
WITH_PYTHON_LAYER := 1 #去掉这个注释,因为以后经常会用到caffe 的 Python layer
然后根据自己的cuda根据该文档提示删去或者注释掉相应的版本的,例如
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \(要根据自己实际才cuda版本注释,文件本身有提示)
将
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib/x86_64-linux-gnu/hdf5/serial(一般是这两条,具体路径可以自己看机器的hdf5文件夹路径)
保存退出。
(3)编译caffe
方法1(传统版):
sudo make all -j16 (在make pycaffe -j16前的话会有很多编译错误,以后的bug)
sudo make runtest -j16(测试)
sudo make pycaffe -j16(警告不用在意,在make all -j16前会好一点,很少error)
sudo make pytest -j16
若报错,则需要
sudo make clean
然后修改错误后,重新编译
方法2(社区版):
sudo mkdir build
sudo cd build
sudo cmake ..
sudo make all -j16
sudo make install -j16
sudo make runtest -j16
(4)检查编译是否成功
从终端进入python
python
import caffe
ctrl + d退出Python
cd caffe (如果不在这个目录下测试,会有bug,好坑)
sudo ./data/mnist/get_mnist.sh #下载数据
sudo ./examples/mnist/create_mnist.sh #把数据改造成lmdb格式
sudo ./examples/mnist/train_lenet.sh #训练模型
8、安装digits(最好参考官网)
方法1,安装digits5.0.0(首选):
# 对于Ubuntu 16.04
CUDA_REPO_PKG=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
ML_REPO_PKG=http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
# 安装repo包
wget "$CUDA_REPO_PKG" -O /tmp/cuda-repo.deb && sudo dpkg -i /tmp/cuda-repo.deb && rm -f /tmp/cuda-repo.deb
wget "$ML_REPO_PKG" -O /tmp/ml-repo.deb && sudo dpkg -i /tmp/ml-repo.deb && rm -f /tmp/ml-repo.deb(这段时间有点问题,假如有错误,则参考本小节最后的提示)
# 安装digits
sudo apt-get update 安装digits
sudo apt-get install digits(首选方式,这种方法只是安装digits5.0.0版本,bug比较小,官网说这个就已经自动附带安装很多依赖)
启动digits
在浏览器中填入:
http://localhost/(这是按照sudo apt-get install digits这种方式安装的打开方法)
按回车即可
#卸载digits
比较容易卸载
sudo apt-get remove digits
sudo apt-get autoremove
注意:这个是老式的装法,虽然官网已经改为下面的方法了,但任然可以用。
方法2,安装digits6.1.0(bug很多):
# For Ubuntu 16.04
CUDA_REPO_PKG=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
ML_REPO_PKG=http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd6
e75d
4.deb
# Install repo packages
wget "$CUDA_REPO_PKG" -O /tmp/cuda-repo.deb && sudo dpkg -i /tmp/cuda-repo.deb && rm -f /tmp/cuda-repo.deb
wget "$ML_REPO_PKG" -O /tmp/ml-repo.deb && sudo dpkg -i /tmp/ml-repo.deb && rm -f /tmp/ml-repo.deb(这段时间有点问题,假如有错误,则参考本小节最后的提示)
# Download new list of packages
sudo apt-get update 安装digits
下载源文件
DIGITS_ROOT=~/digitsgit
clone https://github.com/NVIDIA/DIGITS.git $DIGITS_ROOT
按照依赖
sudo pip install -r $DIGITS_ROOT/requirements.txt
sudo pip install -e $DIGITS_ROOT
启动
cd ~/digitsgit
./digits-devserver
http://localhost:5000
卸载:
这个卸载直接删除digits文件夹便可,因为是直接克隆下来的.
注意:
1, digits6.1.0的bug很多,我碰到最多的问题是尽管caffe用命令行可以使用cudnn,但是在digits6.1.0就经常有下面这个错误
“cudnn_conv_layer.cpp:53] Check failed: status == CUDNN_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR”
而我最后还是不知道怎么搞,一个星期的时间还是搞不定,所以放弃了,选择了安装digits5.0.0。
2, digits是需要cudnn的,所以显卡计算能力小于3的电脑没办法用digits.
提示:在安装digits的时候,有一个bug是:
Failed to add GPGKEY at http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/7fa2af80.pub to apt keys.
可以参考帖子解决,我已经解决。
常见错误汇总
错误:ImportError: No module named caffe原因:就是说没有在bash的引用的环境变量中添加caffe
解决方法:
sudo gedit /etc/profile
export PYTHONPATH=$PYTHONPATH:/home/learning/caffe/python #这个结合自己自身电脑caffe文件夹下哒python文件夹路径设置
source /etc/profile
如果还报错,那就之前没有编译好caffe,所以从第6步开始:
make clean
make all
make pycaffe -j16
make test -j16
make runtest -j16
错误:ImportError: No module named skimage.io
解决方法:
sudo apt-get install python-skimage
sudo apt-get update
错误:python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
解决方法:
cd caffe 进入caffe根目录
打开Makefile.config,在PYTHON_INCLUDE上,将路径设置为
/usr/local/lib/python2.7。
将原来/usr/include/python2.7的文件全部复制到/usr/local/lib/python2.7下。
错误:./train_lenet.sh: 4: ./train_lenet.sh: ./build/tools/caffe: not found
原因:因为错误提示找不到caffe工具,但工具存在,所以要在caffe根目录下执行,才可以寻找到其他目录的路径。
解决方法:
cd caffe
./examples/mnist/train_lenet.sh
错误:Cannot use GPU in CPU-only Caffe: check mode.
原因:因为在make caffe的时候,把Makefile.config设置成了只要CPU计算
解决方法:所以需要把mnist文件夹下的lenet_solver.prototxt改成CPU训练。
错误:mdb_status == 0 (2 vs. 0) No such file or directory
原因:因为没有准备好数据
解决方法:
./caffe/data/mnist/get_mnist.sh #下载数据
./caffe/examples/mnist/create_mnist.sh #把数据改造成lmdb格式
./caffe/examples/mnist/train_lenet.sh #训练模型
错误:AttributeError: 'google.protobuf.pyext._message.RepeatedScalarConta' object has no attribute '_value
原因:因为你的protobuf的版本不对造成的,用pip install protobuf安装的版本号默认是最新的3.2.0。但是caffe不支持高于3.0.0版本的protobuf。
解决方法:
pip uninstall protobuf(卸载当前protobuf)
pip install protobuf==2.6.1(再指定安装低版本的,版主这里用的是2.6.1)
注意:发现在终端安装protobuf的时候,是将其安装到python3.5中,我的解决方法是同时在python3.5,python2.7中收索protobuf相关的文件。之后复制3.5里边有关protobuf的文件替换掉2.7里边相应的protobuf文件。
错误:Exception: "dot" not found in path.
解决方法:
安装:sudo apt-get insall graphviz
然后安装pydot:pip install pydot
错误:Check failed: status == CUDNN_STATUS_SUCCESS (6 vs. 0) CUDNN_STATUS_ARCH_MISMATCH
原因:项目默认是开启cudnn的,而CUDNN要求GPU CUDA Capability 不小于3.0(对于不满足条件的GPU,需要在项目中关闭CUDNN。preprocessor definitions 里面删除USE_CUDNN,也就是说本机显卡不支持cudnn。所以需要Makefile.config中注释掉USE_CUDNN这行,重新编译caffe。
解决方法:
sudo gedit caffe/Makefile.config
注释掉USE_CUDNN
make all
进入python
import caffe (测试)
错误: File "/home/ly/caffe/python/caffe/pycaffe.py", line 13, in <module>
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: No module named _caffe
原因:提示说在 "/home/ly/caffe/python/caffe/pycaffe.py"中需要用到几个梯度优化,但是没有模块叫caffe,因为没编译好pycharm,所以python接口不完善
解决方法:
cd caffe
sudo make clean
sudo make pycaffe
错误:Check failed: error == cudaSuccess (38 vs. 0) no CUDA-capable device is detected
原因:是cudn、cudnn出错了,
进入 samples/bin/x86_64/linux/release,
./deviceQuery(运行deviceQuery),可以测试
解决方法:
我是重装cudn、cudnn
错误:E: Sub-process /usr/bin/dpkg returned an error code (1)
原因:缺失依赖包
解决方法:
sudo apt-get check
sudo apt-get clean
sudo apt-get install -f
错误:Unsupported gpu architecture 'compute_20
原因:cuda版本与兼容性
解决方法:
sudo gedit Makefile.config
然后根据自己的cuda根据该文档提示注释掉相应的版本的
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
错误:[ FAILED ] RMSPropSolverTest/0.TestSnapshotShare, where TypeParam = caffe::GPUDevice<float>
原因:可能是因为配置了多显卡环境,可以使用安装CUDA时运行./deviceQuery时标注的0号GPU("Device 0")跑跑测试试试看。
解决方法:
export CUDA_VISIBLE_DEVICES=0
然后重新make runtest
错误: [ FAILED ] RMSPropSolverTest/0.TestSnapshot, where TypeParam = caffe::CPUDevice<float>
原因:如果使用了Intel MKL作为BLAS,可能是Intel MKL的浮点数计算功能没有设置正确。
方法:使用如下命令:
export MKL_CBWR=AUTO
然后重新make runtest
我的Makefile.config内容:
## Refer to http://caffe.berkeleyvision.org/installation.html # Contributions simplifying and improving our build system are welcome! # cuDNN acceleration switch (uncomment to build with cuDNN). USE_CUDNN := 1 # CPU-only switch (uncomment to build without GPU support). # CPU_ONLY := 1 # uncomment to disable IO dependencies and corresponding data layers # USE_OPENCV := 0 # USE_LEVELDB := 0 # USE_LMDB := 0 # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary) # You should not set this flag if you will be reading LMDBs with any # possibility of simultaneous read and write # ALLOW_LMDB_NOLOCK := 1 # Uncomment if you're using OpenCV 3 # OPENCV_VERSION := 3 # To customize your choice of compiler, uncomment and set the following. # N.B. the default for Linux is g++ and the default for OSX is clang++ # CUSTOM_CXX := g++ # CUDA directory contains bin/ and lib/ directories that we need. CUDA_DIR := /usr/local/cuda # On Ubuntu 14.04, if cuda tools are installed via # "sudo apt-get install nvidia-cuda-toolkit" then use this instead: # CUDA_DIR := /usr # CUDA architecture setting: going with all of them. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility. # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility. CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \ -gencode arch=compute_35,code=sm_35 \ -gencode arch=compute_50,code=sm_50 \ -gencode arch=compute_52,code=sm_52 \ -gencode arch=compute_60,code=sm_60 \ -gencode arch=compute_61,code=sm_61 \ -gencode arch=compute_61,code=compute_61 # BLAS choice: # atlas for ATLAS (default) # mkl for MKL # open for OpenBlas BLAS := atlas # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. # Leave commented to accept the defaults for your choice of BLAS # (which should work)! # BLAS_INCLUDE := /path/to/your/blas # BLAS_LIB := /path/to/your/blas # Homebrew puts openblas in a directory that is not on the standard search path # BLAS_INCLUDE := $(shell brew --prefix openblas)/include # BLAS_LIB := $(shell brew --prefix openblas)/lib # This is required only if you will compile the matlab interface. # MATLAB directory should contain the mex binary in /bin. # MATLAB_DIR := /usr/local # MATLAB_DIR := /Applications/MATLAB_R2012b.app # NOTE: this is required only if you will compile the python interface. # We need to be able to find Python.h and numpy/arrayobject.h. PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include # Anaconda Python distribution is quite popular. Include path: # Verify anaconda location, sometimes it's in root. # ANACONDA_HOME := $(HOME)/anaconda # PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ # $(ANACONDA_HOME)/include/python2.7 \ # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include # Uncomment to use Python 3 (default is Python 2) # PYTHON_LIBRARIES := boost_python3 python3.5m # PYTHON_INCLUDE := /usr/include/python3.5m \ # /usr/lib/python3.5/dist-packages/numpy/core/include # We need to be able to find libpythonX.X.so or .dylib. PYTHON_LIB := /usr/lib # PYTHON_LIB := $(ANACONDA_HOME)/lib # Homebrew installs numpy in a non standard path (keg only) # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include # PYTHON_LIB += $(shell brew --prefix numpy)/lib # Uncomment to support layers written in Python (will link against Python libs) WITH_PYTHON_LAYER := 1 # Whatever else you find you need goes here. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/include/hdf5/serial LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib/x86_64-linux-gnu/hdf5/serial # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies # INCLUDE_DIRS += $(shell brew --prefix)/include # LIBRARY_DIRS += $(shell brew --prefix)/lib # NCCL acceleration switch (uncomment to build with NCCL) # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0) # USE_NCCL := 1 # Uncomment to use `pkg-config` to specify OpenCV library paths. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) # USE_PKG_CONFIG := 1 # N.B. both build and distribute dirs are cleared on `make clean` BUILD_DIR := build DISTRIBUTE_DIR := distribute # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 # DEBUG := 1 # The ID of the GPU that 'make runtest' will use to run unit tests. TEST_GPUID := 0 # enable pretty build (comment to see full commands) Q ?= @
相关文章推荐
- Ubuntu 16.04+CUDA 9.1+cuDNN v7+OpenCV 3.4.0+Caffe+PyCharm 完全安装指南,国内最全!(适用CUDA 9.0)
- Ubuntu 16.04+CUDA 9.1+cuDNN v7+OpenCV 3.4.0+Caffe+PyCharm 完全安装指南,国内最全!(适用CUDA 9.0)
- Caffe深度学习入门——Ubuntu16.04 + CUDA9.1+cudnn7.5 + opencv3.3.1+python3.5+caffe安装参考博客和跳坑笔记
- 史上最全的ubuntu16.04安装nvidia驱动+cuda9.0+cuDnn7.0
- ubuntu16.04下安装CUDA cuDNN及tensorflow-gpu版本及caffe-gpu过程
- Ubuntu16.04环境下安装CUDA、cudnn、Caffe、Tensorflow、pytorch
- Ubuntu16.04下安装NVIDIA驱动、CUDA、cuDNN、OpenCV、Caffe和ROS
- Ubuntu16.04安装NVIDIA驱动+CUDA9.0+cuDNN7.0
- Ubuntu16.04+CUDA8.0+cudnn7.5+Caffe安装过程
- 史上最全的ubuntu16.04安装nvidia驱动+cuda9.0+cuDnn7.0
- Ubuntu 16.04下安装CUDA8.0+Cudnn+Caffe
- ubuntu16.04 安装CUDA 8.0 和 cuDNN 5.1 /cudnn6.0,可适用于gpu版本的(tensorflow,caffe,mxnet)
- Ubuntu16.04+CUDA8.0+cudnn7.5+Caffe安装过程
- Ubuntu16.04 安装 CUDA、CUDNN、OpenCV 并用 Anaconda 配置 Tensorflow 和 Caffe 详细过程
- Ubuntu16.04 nvidia显卡驱动 cuda9.0 cudnn7.0.5 简要配置流程
- 学习Caffe(一)Ubuntu 16.04 安装Caffe+cuda+cudnn+pycaffe+matcaffe
- Ubuntu16.04+anaconda+cuda+cudnn+caffe+opencv新手曲折安装之路
- ubuntu16.04+CUDA本地安装+cuDNN本地安装+tensorflow
- Ubunt16.04安装CUDA cuDNN OpenCV Caffe完整教程
- ubuntu 16.04 安装 tensorflow-gpu 包括 CUDA ,CUDNN,CONDA