http://blog.csdn.net/autocyz/article/details/52299889 http://blog.csdn.net/kexinmcu/article/details/53177238 http://blog.csdn.net/kexinmcu/article/details/53177238 http://blog.csdn.net/u010459819/article/details/53057171?locationNum=1&fps=1 #两天就搞定了确实有点不敢相信
1、安装NVIDIA驱动
首先去官网上查看适合你GPU的驱动(http://www.nvidia.com/Download/index.aspx?lang=en-us) 例如,本人的GPU适合的驱动如图:
点击Search(反应比较慢),但很重要!!!不要安装错了显卡驱动。有可能会导致编译caffe时,出现莫名其妙的错误。
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-384 # 这是我的显卡驱动型号
重启系统,使新驱动生效。测试是否安装成功
nvidia-smi # 或者 nvidia-settings
2、安装CUDA
1 下载并安装CUDA
Cuda是Nvidia的编程语言平台,想使用GPU就必须要使用Cuda。这是下载的网址https://developer.nvidia.com/cuda-release-candidate-download 。因为现在官网上只有Cuda-9.0和Cudnn-7以上的版本。 这里我分享给大家的我的云盘(包括Cuda8.0和Cudnn5.1安装包),免得大家费时间去查找。https://pan.baidu.com/s/1kW8uwkv
载完cuda8.0后,执行如下语句:
sudo sh cuda_8.0.27_linux.run
安装选项如图下所示:
2 下载后完成修改环境变量,然后修改环境变量。
sudo gedit ~/.bashrc #修改环境变量 最好在在前面加上 cd ~
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH # 这个是CuDNN的路径
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
source ~/.bashrc 使环境变量生效
sudo gedit /etc/profile #修改动态环境变量 最好在在前面加上 cd ~
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
########################## 二选一 #######################
sudo gedit /etc/ld.so.conf.d/cuda.conf #创建链接 前面最好加cd ~
/usr/local/cuda/lib64 #在打开文档后添加
sudo ldconfig # 使库生效 完成之后重启
##########################################################
sudo gedit ~/.bash_profile #打开.bash_profile # 最好进入根目录下进行修改
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda
source ~/.bash_profile #使更改的环境变量生效
3.编译测试cuda例子与测试,在命令行输入:
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
这里报错是应为Ubuntu16.04自带的gcc5.x版本CUDA不兼容,所以需要降低gcc+版本
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
打印类似如下信息,说明装成功
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 950M"
CUDA Driver Version / Runtime Version 9.0 / 8.0
CUDA Capability Major/Minor version number: 5.0
Total amount of global memory: 2003 MBytes (2100232192 bytes)
( 5) Multiprocessors, (128) CUDA Cores/MP: 640 CUDA Cores
GPU Max Clock rate: 1124 MHz (1.12 GHz)
Memory Clock rate: 1001 Mhz
Memory Bus Width: 128-bit
L2 Cache Size: 2097152 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 1 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 950M
Result = PASS
3、安装CUDNN
首先去官网下载你需要的cudnn,下载的时候需要注册账号。选择对应你cuda版本的cudnn下载。这里我下载的是cudnn5.1,是个压缩文件(.tgz)——— 编译https://developer.nvidia.com/rdp/cudnn-download
sudo tar -zxvf ./cudnn-8.0-linux-x64-v5.1.tgz #解压文件
cd cuda/include #这是进入解压之后的include文件
sudo cp cudnn.h /usr/local/cuda/include #复制头文件
sudo cp lib* /usr/local/cuda/lib64/ #复制动态链接库
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5 #生成软衔接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
4、安装MATLAB2014A
1.从http://pan.baidu.com/s/1qYJ9tNm 下载Matlab2014的linux版本及**文件
2.下载完成后将iso文件挂载到Linux
sudo mkdir /media/matlab
mount -o loop path/filenam.iso /media/matlab
# mount -o loop /home/tony /Downloads/matlab/MATHWORKS_R2014A.iso /media/matlab 按照需要修改
cd /media/matlab
sudo ./install
3 .安装过程中使用readme.txt中的***
4 .安装完成后使用*****下的 license进行**
5 .首先写入编写命令,然后将*****文件夹下的 libmwservices.so 拷贝到 /usr/local/MATLAB/R2014A/bin/glnxa64
sudo chmod -R a+w /usr/local/MATLAB
6 .建立快捷使用Sudo matlab
sudo apt-get install matlab-support
安装后根据提示输入matlab的安装路径–(/usr/local/MATLAB/R2014A/),确认即可,用户权限不填,表示所有人都可以用,gcc选否,然后可以在命令窗口输入 sudo matlab 启动了。
5、安装OpenCV3.3.0
1.从官网上下载opencv3.3.0 (http://opencv.org/releases.html)的源代码并将其解压到你要安装的位置,进入下载文件的目录,如果是用Ubuntu火狐下载,那么默认是home/你的电脑名字/下载
cd home/你的电脑名字/下载 #需要根据具体的路径进行修改
unzip opencv-3.1.0.zip
cd opencv-3.1.0
mkdir build
2.安装opencv需要的一些依赖项
sudo apt-get -y remove ffmpeg x264 libx264-dev
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
3.编译OpenCV,先进入OpenCV的文件夹
cd ~/tony #这是我OpenCV的文件夹
mkdir build #新建一个build文件夹,编译的工程都在这个文件夹里
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" ..
#需要点时间比较大约10-20分钟,不用管它。
make -j4 #这是编译花费的时间跟你电脑配置相关,我的笔记本是CPU是4核的所以选-j4
sudo make install #安装OpenCV很重要的一步,上一步是编译,这步是安装
4.检验安装,输入以下指令查看OpenCV版本号
pkg-config --modversion opencv
6、安装Caffe
1.首先安装各种依赖包
sudo apt-get update
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y--no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y python-pip
sudo apt-get install -y python-dev
sudo apt-get install -y python-numpy python-scipy
2.安装caffe
cd ~
git clone https://github.com/BVLC/caffe.git #从github上git caffe
cd caffe #打开到刚刚git下来的caffe
sudo cp Makefile.config.example Makefile.config #将Makefile.config.example的内容复制到Makefile.config
#因为make指令只能make Makefile.config文件,而Makefile.config.example是caffe给出的makefile例子
sudo gedit Makefile.config #打开Makefile.config文件
这是我的Makefile.config文件,改过的地方我都标注了change ,可以对照修改。
## 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 **#change** # 安装CUDA里面有一指标 CUDA Capability...如果小于3则不建议修改此项
# 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 **# change**
# 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_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
**#这里删除掉了gencode arch=compute_20,code=sm_20 免得报错**
# 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
MATLAB_DIR := /usr/local/MATLAB **#change**
MATLAB_DIR := /usr/local/MATLAB/R2014a **#change**
# 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 **#change**
# Whatever else you find you need goes here.
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
#LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
INCLUDE_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 /usr/lib/x86_64-linux-gnu/hdf5/serial **#change**
# 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 ?= @
接下来是修改Makefile文件(Ubuntu 的gedit命令很注意大小写!!如果打错了,则会创建一个新的文件进行修改)
sudo gedit Makefile
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS) #将这个修改成下面那个 --ctrl+f查找
NVCCFLAGS +=-D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
3编译caffe
cd ~ /caffe #这是我的caffe目录
sudo apt-get install python-opencv #安装cython, python-opencv
sudo pip install cython easydict
sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearnpython-skimage python-h5py python-protobuf python-leveldb python-networkx python-nosepython-pandas python-gflags Cython ipython #安装依赖库这里跟上面的一些是重复的,因为我是想编译FRCNN 所以我把我要用的包重现安装一遍。
make pycaffe #编译caffe的python接口
sudo gedit /etc/profile #添加~/caffe/python到$PYTHONPATH:
# 添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
source /etc/profile # 使编译环境生效
sudo apt-get install protobuf-c-compiler protobuf-compiler
sudo make clean #第一编译不用添加,如果编译失败必须增需要添加。
sudo make all -j4 # 这里最好是用这个以免编译出现很奇怪的错误
make runtest #运行caffe runtest
成功如下所示:
4.到了一步那就要恭喜你了,caffe环境马上就安装好了,测试安装,成功如下所示:
sh data/mnist/get_mnist.sh
sh examples/mnist/create_mnist.sh
sh examples/mnist/train_lenet.sh
本人在安装caffe过程出现的问题,正在整理争取出一个问题简集。
安装Pycharm
将下载的安装包提取到指定文件夹,然后进去文件夹,右键从此打开终端 sudo sh ./pycharm.sh 即可像Window 下安装一样进行.
** 网址 : http://idea.imsxm.com/
PS:附上搜狗输入法安装步骤
安装命令:
sudo apt-get install fcitx libssh2-1
wget "http://pinyin.sogou.com/linux/download.php?f=linux&bit=64" -O "sougou_64.deb"
sudo dpkg -i sougou_64.deb
出现的问题:
dpkg: 处理归档 sougou_64.deb (--install)时出错:
无法访问归档文件: 没有那个文件或目录
在处理时有错误发生:
正在读取数据库 ... 系统当前共安装有 218082 个文件和目录。)
正准备解包 sougou_64.deb ...
正在解包 sogoupinyin (2.1.0.0086) ...
dpkg: 依赖关系问题使得 sogoupinyin 的配置工作不能继续:
sogoupinyin 依赖于 libopencc2 | libopencc1;然而:
未安装软件包 libopencc2。
未安装软件包 libopencc1。
sogoupinyin 依赖于 fcitx-libs (>= 4.2.7);然而:
未安装软件包 fcitx-libs。
sogoupinyin 依赖于 fcitx-libs-qt (>= 4.2.7);然而:
未安装软件包 fcitx-libs-qt。
解决办法
sudo apt-get install -f
|
请发表评论