Ubuntu16 安装 caffe
来源:互联网 发布:ubuntu安装jdk tar.gz 编辑:程序博客网 时间:2024/06/05 20:21
一、前言
不得不说在搭建caffe环境的时候自己走了不少弯路,这里我记录一下我的安装经历,希望对大家有帮助。建议大家先仔细看看官方文档,尤其是第一次接触的人,弄清一下基本概念官方文档1,文档2。
二、安装NVIDIA显卡驱动
如果没有显卡这步可以跳过
网上很多人说要进入tty,然后关掉lightdm,其实根本没有必要完全是,怎家复杂度,混淆视听
sudo add-apt-repository ppa:graphics-drivers/ppasudo apt-get updatesudo apt-get install nvidia-352 nvidia-settings nvidia-prime
重启电脑 重启之后,记得查询一下prime-select query查看当前正在使用的显卡$ prime-select querynvidia输入 cat /proc/driver/nvidia/version 查看正在使用的 nvidia 驱动版本和编译时采用的 gcc 版本
三、安装cuda8.0
如果没有显卡这步可以跳过。
首先从NVIDIA官网下载cuda8.0的deb包,记得一定要下载deb包,这个安装简单
然后输入下面的命令安装
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb sudo apt-get updatesudo apt-get install cuda
安装完之后,配置环境变量export PATH=/usr/local/cuda-8.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH 安装 cuda 后,或许之前安装的显卡驱动会被 cuda 里的驱动覆盖掉一部分。此时不妨再次运行显卡驱动安装命令来检查一下是不是有需要重新安装的部分:sudo apt-get install nvidia-352四、安装anacondaanaconda的python里面集成了很多包,ipython,mkl,numpy等都预装了,可以在这注册,下载证书,安装anaconda./Anaconda-2.3.0-Linux-x86_64.sh关掉终端,重新打开先执行sudo chown -R ws2 anaconda2sudo chown -R usr foldername安装accelerateconda update condaconda install accelerateconda install iopro接下来拷贝anaconda的许可文件到用户主目录mv license_academic_20150611072013.txt ~/.continuum然后升级ipythonconda update ipython会爆一个IO错误,将错误信息到Google上搜一下就会有答案测试一下 输入ipythonimport mklmkl.set_num_threads(4) # 设置最大线程数mkl.get_max_threads() # 查看当前线程数五、安装opencv用一个脚本安装就行了。# KEEP UBUNTU OR DEBIAN UP TO DATEsudo apt-get -y updatesudo apt-get -y upgradesudo apt-get -y dist-upgradesudo apt-get -y autoremove# INSTALL THE DEPENDENCIES# Build tools:sudo apt-get install -y build-essential cmake# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake):sudo apt-get install -y qt5-default libvtk6-dev# Media I/O:sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev# Video I/O:sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev# Parallelism and linear algebra libraries:sudo apt-get install -y libtbb-dev libeigen3-dev# Python:sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy# Java:sudo apt-get install -y ant default-jdk# Documentation:sudo apt-get install -y doxygen# INSTALL THE LIBRARY (YOU CAN CHANGE '3.2.0' FOR THE LAST STABLE VERSION)sudo apt-get install -y unzip wgetwget https://github.com/opencv/opencv/archive/3.2.0.zipunzip 3.2.0.ziprm 3.2.0.zipmv opencv-3.2.0 OpenCVcd OpenCVmkdir buildcd buildcmake -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON ..make -j4sudo make installsudo ldconfig# EXECUTE SOME OPENCV EXAMPLES AND COMPILE A DEMONSTRATION# To complete this step, please visit 'http://milq.github.io/install-opencv-ubuntu-debian'.六、安装MKL去网上搜下载mkl,然后解压,然后运行install.sh就行了然后就是配置环境变量sudo vim /etc/ld.so.conf.d/intel_mkl.conf/opt/intel/lib/intel64_lin/opt/intel/mkl/lib/intel64sudo ldconfig七、安装Boost运行下面代码sudo apt-get install libboost-all-dev八、其他依赖项sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compilersudo apt-get install --no-install-recommends libboost-all-devsudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compilersudo apt-get install -y build-essential cmake git pkg-configsudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler libatlas-base-dev libgflags-dev libgoogle-glog-dev liblmdb-devsudo apt-get install the python-devsudo apt-get install -y python-pipsudo apt-get install -y python-devsudo apt-get install -y python-numpy python-scipy # (Python 2.7 development files)九、下载caffegit clone https://github.com/BVLC/caffe.git安装Python的pip和easy_installwget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py python ez_setup.py --insecurewget https://bootstrap.pypa.io/get-pip.pypython get-pip.py安装python依赖cd caffe/pythonfor req in $(cat requirements.txt); do sudo pip install $req; done十、编译caffecd caffe cp Makefile.config.example Makefile.config vim Makefile.config 下面是我的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 := 1# 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.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# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := mkl# 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/local/include /usr/include/hdf5/serialLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/share/OpenCV/3rdparty/lib/# 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 := buildDISTRIBUTE_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 ?= @然后make allmake testmake runtestmake pycaffe完成之后配置python环境sudo gedit ~/.bashrc
在下面这两句话前面加上“#”注释掉
#export PATH="/home/ks/anaconda2/bin:$PATH"
#export LD_LIBRARY_PATH="/home/ks/anaconda2/lib:$LD_LIBRARY_PATH"
配置caffe环境
PYTHONPATH=/home/username/caffe/python:$PYTHONPATH
export PYTHONPATH
重启电脑
安装protobuf
pip install protobuf
安装scikit-image
pip install -U scikit-image
参考链接:http://caffe.berkeleyvision.org/installation.html
http://gwang-cv.github.io/2016/10/21/Ubuntu16.04+Titan%20X+CUDA8.0+cudnn5/
http://coldmooon.github.io/2015/08/03/caffe_install/
0 0
- ubuntu16.04安装caffe
- Ubuntu16.04 安装caffe
- Ubuntu16.04 安装caffe
- Ubuntu16.04 Caffe安装
- Ubuntu16.04 安装Caffe
- Ubuntu16.04 安装Caffe
- Ubuntu16 安装 caffe
- Ubuntu16.04安装Caffe
- ubuntu16.04 安装 caffe
- Ubuntu16.04安装caffe
- ubuntu16.04 安装 Caffe
- ubuntu16.04安装Caffe
- Ubuntu16+TitanX+Cuda8 安装 caffe
- ubuntu16.04安装caffe详解
- ubuntu16.04下安装caffe
- ubuntu16.04安装bvlc/caffe
- 虚拟机ubuntu16.04 安装caffe
- Ubuntu16.04 Caffe安装笔记
- 【笔记】SpringMVC系列框架 [ 2 ]
- 2. js中的 || 与 && 运算符
- 基于android的Socket通信
- javascript-正则表达式-支持正则的string方法
- linux下IPTABLES配置详解
- Ubuntu16 安装 caffe
- foreach循环
- 必须了解的数据库30条军规解读
- 静态构造函数
- C++调用WPF的dll
- 第一天定向爬虫学习笔记
- 时间戳和日期时间Timestamp的转化
- ROS开机自启动
- 使用ContentObserver监听短信