ubuntu16.04 LTS安装CUDA9.0+cudnn7.5.0+tensorflow+caffe
花了好几天的时间安装软件。。。终于安好了
主要参考如下:
(1)Ubuntu16.04+1080下配置Tensorflow - DFan的NoteBook - ****博客 https://blog.****.net/u011974639/article/details/72851153#step-1%E5%AE%89%E8%A3%85%E6%96%B0%E7%89%88%E6%98%BE%E5%8D%A1%E9%A9%B1%E5%8A%A8
(2)TensorFlow安装(Ubuntu18.04+Anaconda3+CUDA9.0+cuDNN7.1+TensorFlow1.8.0+Pycharm) - 李岩的博客 - 博客园 https://www.cnblogs.com/lydbky/p/9348112.html
(3)Ubuntu16.04安装配置Caffe教程(GPU版) - yggaoeecs的博客 - ****博客 https://blog.****.net/yggaoeecs/article/details/79163789
(4)Ubuntu16.04 Caffe 安装步骤记录(超详尽) - yhao的博客 - ****博客 https://blog.****.net/yhaolpz/article/details/71375762
(5)呕心沥血一个月之caffe安装与配置 - little豪斯 - ****博客 https://blog.****.net/sinat_35188997/article/details/73530434
我安装的是cuda9.0+cudnn7.5.0
具体细节都在前面的链接里,大致过程就是
(1)卸载原来的显卡驱动,安装新的显卡驱动
(2)安装cuda>安装cudnn
(3)安装anaconda(通过anaconda来安装tensorflow1.11)
接下来是安装GPU版本的caffe
首先安装OpenCV:
安装相关依赖包(有的安装教程里没有提到要安装相关依赖包,但为了保险起见我个人安装了依赖包,具体哪些依赖包参考(5))
在Releases – Page 3 https://opencv.org/releases/page/3/ 下载opencv相应版本的的Sources压缩文件
然后unzip opencv-3.2.0.zip解压
cd opencv-3.2.0目录下
mkdir build
cd build
cmake cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8(这里可能编译不成功,我当时下载了opencv3.2以及OpenCV3.3版本的,3.2版本没编译成功,3.3版本的编译成功了)
sudo make install (这一步就是安装啦,3.3版本的安装成功)
然后查看opencv版本
pkg-config --modversion opencv(如果未找到命令就是没安装成功,虽然我在sudo make install那一步显示安装成功,但这一步未找到命令,于是重新装了一遍,安装成功之后就会显示响应的opencv版本)
接下来就是安装caffe啦:
首先安装相关依赖包(这个依赖包有点多。。在安装过程中可能出现E:Failed to fetch http:XXX,可以重试几遍可能会成功安装,如果实在不行就在terminal输入:echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null再sudo apt-get update就ok 顺便说一下,我直接在 /etc/resolv.conf下添加一行nameserver 8.8.8.8并没有解决Failed to fetch http:XXX的问题。。这个主要是DNS的问题)
接下来clone:
git clone https://github.com/BVLC/caffe.git(当然啦也可以不用clone,直接在网站下载就好啦)
cd caffe
sudo cp Makefile.config.example Makefile.config(将 Makefile.config.example 文件复制一份并更名为 Makefile.config )
然后开始配置啦
(1)配置Makefile.config
这里要说一下除了教程里提到的修改部分(其实就是去掉注释)还需要在
# 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.
下面注释掉(其实就是把它删掉就好了)相应的行,否则会出现nvcc fatal : Unsupported gpu architecture 'compute_20'的问题(刚开始并不知道是因为这个原因,然后我折腾了好久。。。)
这三个注释下面是这样的
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_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
我安装的是cuda9.0,根据# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.提示需要注释掉*_20 and *_21 lines于是删掉了这两行,变成
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
参考了: https://blog.****.net/weixin_37983220/article/details/85341058
(2)配置Makefile 文件
重点提一下:参考教程里说将LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5改成LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
但是!!!
我的Makefile文件里是介样的
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
LIBRARIES += hdf5_hl hdf5(我这里是两行不是一行!!!!)
我直接将LIBRARIES += hdf5_hl hdf5改成LIBRARIES +=hdf5_serial_hl hdf5_serial
(3)根据教程修改 /usr/local/cuda/include/host_config.h 文件
#error-- unsupported GNU version! gcc versions later than 4.9 are not supported! 改为
改成//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
问题又来了。。我的 /usr/local/cuda/include/host_config.h文件里没有#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!这一行,真的不是我老眼昏花o(╥﹏╥)o
如果没有这一行的话就不用改啦,
配置好之后
make all -j8(顺利进行完这一步感觉太不容易了╭(╯^╰)╮)
编译成功之后测试
sudo make runtest -j8
这一步又出错了libcudart.so.9.0: can't open shared object file: No such f
主要原因大概是因为没找到这个库
查了一下说可以重新配置一下或者安装这个库
但是对我不顶用
看到有博主说不用加权限直接
make runtest -j8
测试成功
之前一直嫌弃太麻烦结果搞到现在才安装好GPU版本的tensorflow以及caffe.....
想学习就不要偷懒唉....