ubuntu 16.04 上安装支持GPU的caffe
来源:互联网 发布:李涛疯狂淘宝怎么样 编辑:程序博客网 时间:2024/06/09 20:04
这两天在ubuntu 16.04上安装caffe-gpu碰了很多壁,老是出现很多莫名其妙的问题,搞得我焦头烂额;直到我找到一个博客教程,很细节,特此梳理一下。
该教程中的caffe来自github的资源(记得检查Makefile是否和caffe版本符合)。
硬件和系统需求
硬件只要能支持cuda8.0和cudnn v6.0以上的就行。系统Ubuntu 16.04。
编译器和Python环境
确保系统有gcc-5 和g++ -5
$ echo $PATH # Should not contain anaconda$ gcc --version # 5.4.0$ g++ --version # 5.4.0$ which python # /usr/bin/python
Nvidia 驱动、cuda-8.0和cudnn安装
因为本文主要是caffe安装,cuda安装参考官方文档和https://ywpkwon.github.io/post/ubuntu-setting/
caffe安装
安装依赖
这里是基于Python2.7安装的,所有依赖也是基于Python2.7:
sudo apt-get updatesudo apt-get upgradesudo apt-get install build-essential cmake git pkg-configsudo apt-get install libleveldb-dev libsnappy-dev libhdf5-serial-devsudo apt-get install libatlas-base-devsudo apt-get install --no-install-recommends libboost-all-devsudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-devsudo apt-get install python-dev # Python 2.7sudo apt-get install python-numpy python-scipy python-pipsudo apt-get install libopencv-dev
protobuf-3.2.0的建立是来自资源。 下载完毕之后解压到本地并用cd命令进入解压后的文件夹。
$ sudo apt-get install autoconf automake libtool curl make unzip$ ./autogen.sh$ ./configure --prefix=/usr/local/ CC=/usr/bin/gcc$ make$ make check$ sudo make install$ sudo ldconfig # refresh shared library cache注意:使用make指令时可以在后面增加 -j8 来用8个cpu内核同时编译,
$ make -j8检查protoc安装结果:
$ protoc --version
下载caffe资源并安装
$ sudo apt-get install git # Run this if git is not installed$ sudo apt-get install vim # Run this if vim is not installed (optional)$ git clone https://github.com/BVLC/caffe
配置 Makefile.config文件
$ cd caffe$ cp Makefile.config.example Makefile.config$ vim Makefile.config # Replace vim by any text editor我这里是安装caffe支持GPU的,所以配置文件里USE_CUDNN := 1这行要去掉注释,配置完后的Makefile.config文件大体如下:
USE_CUDNN := 1CUDA_DIR := /usr/local/cudaCUDA_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_61BLAS := atlasPYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include \ /usr/local/lib/python2.7/dist-packages/numpy/core/includePYTHON_LIB := /usr/libWITH_PYTHON_LAYER := 1INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/BUILD_DIR := buildDISTRIBUTE_DIR := distributeTEST_GPUID := 0Q ?= @
注意:你安装的cuda版本可能不支持架构compute_20或者其他架构,只要将CUDA_ARCH := ....这里包含compute_20的那一行删除就行。
为hdf5建立符号链接:
$ cd /usr/lib/x86_64-linux-gnu$ sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so$ sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so
这一步很重要,如果这不没有,会报/usr/bin/ld: -lhdf5找不到。
编译
$ make all -j8$ make test$ make runtest$ make distribute # To use with python编译make all -j8时可能还会报找不到opencv的错,比如:
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'.build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'collect2: error: ld returned 1 exit statusMakefile:617: recipe for target '.build_release/test/test_convolution_layer.testbin' failedmake: *** [.build_release/test/test_convolution_layer.testbin] Error 1这里只要修改Makefile文件(不是Makefile.config文件),增加一行就行:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
最后当执行到make test时仍然可能会报上面这个错误,直接忽视,直接执行make runtest这一条命令,如果全部通过就行大功告成了。
本文参考教程https://gear.github.io/2017-03-30-caffe-gpu-installation/
阅读全文
1 0
- ubuntu 16.04 上安装支持GPU的caffe
- Ubuntu 14.04上Caffe安装:CPU-Only与GPU支持
- ubuntu安装caffe +gpu
- ubuntu 16.04 安装caffe GPU版本时遇到的问题
- Ubuntu安装Caffe(无GPU)
- Ubuntu 16.04 安装 Tensorflow(GPU支持)
- Ubuntu 16.04 安装 TensorFlow(GPU支持)
- Ubuntu 16.04上安装Caffe
- Ubuntu 16.04 + cuda8.0 + opencv3 + caffe的安装,tensorflow-gpu的安装
- Ubuntu环境下安装GPU版本的caffe
- ubuntu 16.04 无GPU版caffe安装简记
- ubuntu 16.04 无GPU版caffe安装简记
- Ubuntu 16.04安装使用--Ubuntu16.04下基于Docker的Caffe-GPU版本环境搭建总结
- 【caffe配置】在ubuntu上配置带gpu版本的caffe
- ubuntu+caffe+gpu 安装配置流程
- Ubuntu 14.04 caffe 无GPU安装配置
- ubuntu安装caffe完整版(GPU)
- 在Macbook Pro上安装支持GPU的TensorFlow
- Zabbix监控平台部署+监控客户端
- Java 几道常见String面试题
- 复杂网络问答
- TP5使用phpmailer出现的错误
- Spring Boot对dubbo的整合
- ubuntu 16.04 上安装支持GPU的caffe
- unity3d之3D贪吃蛇
- 欢迎使用CSDN-markdown编辑器
- Android属性动画之 一、 ValueAnimator
- nginx 负载均衡个服务器之间文件共享
- 初步了解Junit与assert
- Eclipse 常见设置和报错问题
- HAProxy系列—keepalived+haproxy实现高可用负载层
- reactNative学习笔记之Props属性