ubuntu 14.04安装
- 先到官网下载ubuntu14.04,网址:http://www.ubuntu.com/download/desktop
ubuntu-14.04.4-desktop-amd64.iso
- 参考:Ubuntu14.04 安装及使用:[1]制作安装U盘 制作安装U盘
然后参考:Ubantu14.04安装教程 安装系统
- 分区:
- boot 200M 主分区
- / 50000M
- swap 4000M
- home 剩余M
cuda7.5安装
- cuda7.5下载:地址 https://developer.nvidia.com/cuda-downloads
文件: cuda_7.5.18_linux.run
- 登录界面前按Ctrl+Alt+F1进入命令提示符 【禁用nouveau驱动】
- 执行命令: sudo vi /etc/modprobe.d/blacklist-nouveau.conf
- 输入以下内容
blacklist nouveau options nouveau modset=0
最后保存退出(:wq)
- 执行命令: sudo update-initramfs -u
再执行命令: lspci | grep nouveau 查看是否有内容
如果没有内容 ,说明禁用成功,如果有内容,就重启一下再查看
sudo reboot
重启后,进入登录界面的时候,不要登录进入桌面,直接按Ctrl+Alt+F1进入命令提示符。
- 重启后,登录界面时直接按Ctrl+Alt+F1进入命令提示符
- 安装依赖项:
sudo service lightdm stop
sudo apt-get install g++
sudo apt-get install git
sudo apt-get install freeglut3-dev
- 假设cuda_7.5.18_linux.run位于 ~ 目录,切换到~目录: cd ~
- 执行命令: sudo sh cude_7.5.18_linux.run
- 安装的时候,要让你先看一堆文字(EULA),我们直接不停的按空格键到100%,然后输入一堆accept,yes,yes或回车进行安装。安装完成后,重启,然后用ls查看一下:
ls /dev/nvidia*
会看到/dev目录下生成多个nvidia开头文件(夹)
或者输入命令:
nvcc –version
会显示cuda版本号则说明安装成功
- 配置环境变量
执行命令: sudo vi /etc/profile
文件底部添加以下内容:
export PATH=/usr/local/cuda-7.5/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
- sample编译
切换到~目录,可以看到当前目录中包含一个文件夹:
NVIDIA_CUDA-7.5_Samples
然后cd切换到NVIDIA_CUDA-7.5_Samples的目录下,输入: sudo make
然后回车执行,大概等个十多分钟后就会把全部的samples编译完毕。
- sample演示
编译完成后,生成可执行文件位于:
~/NVIDIA_CUDA-7.5_Samples/bin/x86_64/linux/release 目录下
eg: 运行 ./nbody 可以看到对应的演示demo
安装CUDA过程中遇到的问题:
- 系统版本:ubuntu14.04.4
在执行命令: sudo apt-get install g++ 的以后出现一下错误:
g++ : Depends: g++-4.8 (>= 4.8.2-5~) but it is not going to be installed
出错原因:
是因为ubuntu 14.04的源过旧或不可访问导致,可以通过更新源解决
- 解决方法:
首先,备份原始源文件source.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
然后并以下添加到/etc/apt/source.list文件末尾
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
最后更新ubuntu 源
sudo apt-get update
问题解决参考: 【ubuntu 14.04 install g++问题"g++:Depends:g++-4.8(>= 4.8.2-5】
安装caffe
- 下载caffe:执行命令: sudo git clone https://github.com/BVLC/caffe.git
- 安装依赖项:
sudo apt-get install libatlas-base-dev
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
sudo apt-get install protobuf-compiler
- 编译caffe
cd ~/caffe
sudo cp Makefile.config.example Makefile.config
make all
- 配置运行环境
sudo vi /etc/ld.so.conf.d/caffe.conf
添加内容:
/usr/local/cuda/lib64
- 更新配置
sudo ldconfig
- caffe测试,执行以下命令:
cd ~/caffe
sudo sh data/mnist/get_mnist.sh
sudo sh examples/mnist/create_mnist.sh
最后测试:
sudo sh examples/mnist/train_lenet.sh
其他安装
## 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 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_50,code=compute_50
# 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/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/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
# 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
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 ?= @
以上为caffe目录中的Makefile.config.example文件内容,可以看到诸如:
# USE_CUDNN := 1
# OPENCV_VERSION := 3
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
都没有生效,以下将依次安装对应的依赖项
opencv3.0安装
- github上有人写了安装各个版本的opencv脚本,很方便,不用自己下载,编译,配置环境等
- 可以到这位作者的百度网盘中下载:
Caffe + Ubuntu 15.04 + CUDA 7.5 新手安装配置指南
【PS:为了方便大家使用,我提供一个百度云盘,用于分享部分安装过程中需要用到的软件包和链接地址(所有软件包仅供学术交流使用,请大家尽量去官网下载。)。百度云盘链接: http://pan.baidu.com/s/1qX1uFHa 密码:wysa 】 作者:【Xin-Yu Ou(欧新宇)】
- 切换到目录: Install-OpenCV-master\Ubuntu
执行命令安装依赖项: sudo sh Ubuntu/dependencies.sh
然后切换到Install-OpenCV-master\Ubuntu\3.0目录
执行命令安装opencv3.0: sudo sh opencv3_0_0.sh
- 现在3.1已经发布了,可以先执行 get_latest_version_download_file获取最新的下载路径,然后更新opencv3_0_0.sh中的下载路径
arch=$(uname -m) if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then flag=1 else flag=0 fi echo "Installing OpenCV 3.0.0" mkdir OpenCV cd OpenCV echo "Removing any pre-installed ffmpeg and x264" sudo apt-get -y remove ffmpeg x264 libx264-dev echo "Installing Dependenices" sudo apt-get -y install libopencv-dev sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev sudo apt-get -y install python-dev python-numpy sudo apt-get -y install libtbb-dev sudo apt-get -y install libqt4-dev libgtk2.0-dev sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev sudo apt-get -y install x264 v4l-utils ffmpeg sudo apt-get -y install libgtk2.0-dev echo "Downloading OpenCV 3.0.0" wget -O opencv-3.0.0.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.0.0/opencv-3.0.0.zip/download echo "Installing OpenCV 3.0.0" unzip opencv-3.0.0.zip cd opencv-3.0.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. make -j8 sudo make install sudo sh -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘ sudo ldconfig echo "OpenCV 3.0.0 ready to be used"
- opencv3安装成功后,更新Makefile.config文件:
启用OpenCV 3.0, 去掉”#”
OPENCV_VERSION =3
opencv3.0安装过程遇到的问题
- 执行sudo sh opencv3_0_0.sh后,有一步被卡住,显示在下载一个文件:
ippicv_linux_20141027.tgz
还是墙的原因
- 从 [其他文档] ippicv_linux_20141027.tgz 下载目标文件,然后拷贝到opencv/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ 目录下即可
- 参见: http://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation
BLAS安装:使用MKL
- MKL(Intel(R) Parallel Studio XE Cluster Edition for Linux 2016)
下载地址: https://software.intel.com/en-us/intel-education-offerings
(上面那位作者网盘也有,不过序列号无法使用,故需自己申请)
- 下载后讲文件放入~目录: parallel_studio_xe_2016.tar.gz
- 依次执行以下命令完成安装:
tar zxvf parallel_studio_xe_2016.tar.gz
chmod a+x parallel_studio_xe_2016 -R
sh install_GUI.sh
- MKL环境配置:
sudo gedit /etc/ld.so.conf.d/intel_mkl.conf
添加以下内容
/opt/intel/lib/intel64
/opt/intel/mkl/lib/intel64
生效
sudo ldconfig -v
- 更新Makefile.config文件
BLAS := mkl
安装cudnn进行加速
- cudnn-7.0-linux-x64-v4.0-rc.tgz下载
网址: https://developer.nvidia.com/cudnn
或者去这位作者网盘: http://pan.baidu.com/s/1bnOKBO
- 将cudnn-7.0-linux-x64-v4.0-rc.tgz放到~目录
- 依次执行以下命令:
sudo tar xvf cudnn-7.0-linux-x64-v4.0-rc.tgz
cd cuda/include
sudo cp *.h /usr/local/include/
cd ../lib64
sudo cp lib* /usr/local/lib/
cd /usr/local/lib
sudo chmod +r libcudnn.so.4.0.4
sudo ln -sf libcudnn.so.4.0.4 libcudnn.so.4
sudo ln -sf libcudnn.so.4 libcudnn.so
sudo ldconfig
- 更新Makefile.config文件 (启用CUDNN,去掉”#” )
USE_CUDNN := 1
重新编译
- j8表示8线程根据自己机器修改,opencv3.0.sh文件中也可以自行修改
sudo make clean
sudo make all -j8
MNIST数据集进行测试
- sh data/mnist/get_mnist.sh
- sh examples/mnist/create_mnist.sh
- sh examples/mnist/train_lenet.sh
运行结果:
其他: 常用vi编辑器命令行
A:当前行的尾部追加内容
i:游标前插入内容
I:游标后插入内容
o:在鼠标所在行的下面添加内容
O:在鼠标所在行的上面添加内容
ESC:退出编辑模式
Ctrl-T:移动到下一个tab
Backspace:向后移动一个字符
Ctrl-U:删除当前
cw:删除游标所在的字符,然后进入编辑模式
cc:删除游标所在的行,然后进入编辑模式
C:删除从游标所在的位置到行尾的字符,然后进入编辑模式
dd:删除当前行
ndd:删除第n行
D:删除当前行游标所在的位置后面的字符
dw:删除邮编所在的字符
d}:删除当前段剩余的字符
d^:删除游标前到行首的字符
c/pat:删除游标后面到第一次匹配字符间的内容
dn:删除游标后面到下一个匹配字符间的内容
dfa:删除当前行游标到匹配字符间的内容(匹配的字符也将被删)
dta:删除当前行游标到匹配字符间的内容(匹配的字符不被删)
dL:删除从游标到屏幕的最后一行之间的内容
dG:删除从游标到文件末尾之间的内容
J:连结上下两行的内容
p:在游标后面插入buffer中的内容
P:在游标前面插入buffer中的内容
rx:用x替换字符
Rtext:用text从游标开始处进行替换
u:撤销最后的改变
U:还原当前行的内容
x:向后删除游标所在位置的字符
X:向前删除游标前面的字符
nX:删除前面的n个字符,游标所在的字符将不会被删
.:还原最后的改变
~:反转字母的大小写
y:拷贝当前行到新的buffer
yy:拷贝当前行
“xyy:拷贝当前行的buffer名为x的buffer
ye:拷贝当单词的末尾
http://www.cnblogs.com/junw_china/articles/1708967.html
参考文献
Caffe + Ubuntu 15.04 + CUDA 7.5 新手安装配置指南
Caffe学习系列(1):安装配置ubuntu14.04+cuda7.5+caffe+cudnn
http://caffe.berkeleyvision.org/installation.html
ubuntu 14.04 install g++问题"g++:Depends:g++-4.8(>= 4.8.2-5
http://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation