Windows 10 + Ubuntu 双系统 caffe + cuda 7.5配置

终于把caffe配置好了,现在分享一下具体的步骤,以及有一些问题的解决方法。

首先强调一下: Ubuntu不能用16.04版本!Cuda不支持!(这就是为什么我不在标题加ubuntu14.04,怕16.04的人看不到)

1. 安装Ubuntu系统

电脑原来的系统是Windows 10,现要安装Ubuntu系统。

参考文章:

http://blog.sina.com.cn/s/blog_de4da5fa0102vjc3.html

http://blog.csdn.net/ubunfans/article/details/47724341

需要的东西:
1)一个不小于2G的U盘
2)下载Ubuntu 14.04.1:http://cdimage.ubuntu.com/netboot/14.04/?_ga=1.70190675.234686859.1470387719
3)下载UltraISO:http://www.cr173.com/soft/15480.html

步骤:
1)插入U盘,注意先把U盘清空;
2)打开UltraISO.v.9.6.2.3059.exe, 文件--打开--选择 ubuntukylin-14.04.1-desktop-amd64.iso, 启动--写入硬盘映像...;

3)这时一定要注意写入的磁盘应是U盘,确认后开始写入;


4)写入需要一定时间,这时候来分配磁盘空间给Ubuntu系统使用。右击 我的电脑--管理--磁盘管理,选择你想要分配的磁盘,右键--压缩卷...--输入你想要的分配的空间大小(1G = 1024MB,至少要有40G),然后会有新的卷出现;

5) 待U盘写入完毕,重启电脑,按F1/F10/F12(不清楚要预先查好)进入BIOS。我的情况较为特殊,直接重启就可以出现安装界面。选择Install UbuntuKylin;


6) 注意,安装系统过程请先断网,wifi也不要连接。进入安装界面后,一直往下走,直到空间分配时,选择最后一项,自行分配;
7) 这时候我们刚刚分配出来的空间会显示free字样,按下面+号开始具体分配四种空间:/, /home, /boot, swap(中文是“交换空间”)。其中/一定要最后一个分配,属于主分区,其他三个顺序无所谓,但是都属于逻辑分区。/,/home,/boot属于ext4挂载。
以我的情况为例,我有100G的free空间。/boot分配了4G,swap分配了200MB, /分配了15G,剩下的空间为/home。
分配好空间,还有一个要注意的点,把引导设置为windows引导,否则以后开机都会直接进入Ubuntu系统。
8)分配完空间后开始安装。如果之前没有断网,这一步会非常的久,所以切记,安装时先断网!
9)若安装无错误,则进入Ubuntu系统。

至此,双系统安装完毕。

** 如果重启电脑发现只会直接进入Ubuntu系统,那么这样:

1)ctrl+alt+t,打开终端,输入sudo update-grub,以我的结果为例:

Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found background image: ubuntu_kylin_grub_bg.tga
Found linux image: /boot/vmlinuz-3.13.0-92-generic
Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
Found Windows 10 (loader) on /dev/sda1
done
从background image为0开始,往下数,windows为第5个;
2)输入sudo gedit /etc/default/grub,将GRUB_DEFAULT=0改为GRUB_DEFAULT=5,保存。在终端中再次输入sudo update-grub,完成后重启就可以看到引导界面了。

2. 配置caffe
需要的东西:
1)cuda 7.5:https://developer.nvidia.com/cuda-downloads
建议下载runfile

2)cuDNN 4.0:https://developer.nvidia.com/cudnn
要先注册一个帐号,才能下载。
注册完登录后,点击Download,进入cuDNN Download Survey,可不填,直接拉到最下面Proceed to Downloads
跳转后,打勾,下载cuDNN 4.0

3) Anaconda for Linux, Python 2.7: https://www.continuum.io/downloads


4) caffe:https://github.com/BVLC/caffe,直接下载zip,下载后解压


步骤:

1) ctrl+alt+t,安装依赖项:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
2)更新显卡驱动:

右上角齿轮icon--系统设置--软件和更新--附加驱动,选择最新的显卡驱动,应用更改,后重新启动,显卡驱动更新完成。

** 若显示显卡不是专用的,则ctrl+alt+t,输入

sudo apt-get install nvidia-331 nvidia-settings nvidia-prime

完成后再重复上面的操作就可以了。

3)安装cuda7.5:
右键cuda7.5文件所在的文件夹,在终端打开,输入sh cuda_7.5.18_linux.run --override
稍等片刻后出现条款,按空白键跳过,输入accept,n(不安装显卡驱动),后面都是y,路径的话直接按enter适用默认路径
4)安装 cuDNN 4.0:
解压cudnn-7.0-linux-x64-v4.0-prod.tgz,解压后的cuda/include文件夹在终端打开

输入

sudo cp cudnn.h /usr/local/cuda/include/
cd ~/cuda/lib64
sudo cp lib* /usr/local/cuda/lib64/
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.4
sudo ln -s libcudnn.so.4.0.7 libcudnn.so.4
sudo ln -s libcudnn.so.4 libcudnn.so
更新环境变量:

sudo gedit /etc/profile
最后加入

PATH=/usr/local/cuda/bin:$PATH
export PATH
保存退出
创建链接文件
sudo vi /etc/ld.so.conf.d/cuda.conf
按i开始编辑,写入
/usr/local/cuda/lib64
按esc键,输入:wq,回车
</pre><pre name="code" class="plain">sudo ldconfig
5)安装cuda sample:
在终端打开/usr/local/cuda/samples,并输入:
sudo make all -j4 #此处的-j4表示用4CPU核处理,根据你的电脑中的CPU数目改变数字
该过程较久,待完成后,
cd bin/x86_64/linux/release
sudo ./deviceQuery
若显示出显卡信息:
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GT 630"
  CUDA Driver Version / Runtime Version          7.5 / 7.5
  CUDA Capability Major/Minor version number:    3.0
  Total amount of global memory:                 2047 MBytes (2146762752 bytes)
  ( 1) Multiprocessors, (192) CUDA Cores/MP:     192 CUDA Cores
  GPU Max Clock rate:                            876 MHz (0.88 GHz)
  Memory Clock rate:                             891 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 262144 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 = 7.5, CUDA Runtime Version = 7.5, NumDevs = 1, Device0 = GeForce GT 630

Result = PASS
即安装成功。
5)安装Atls:
sudo apt-get install libatlas-base-dev 
6)配置Python
方法1:安装Anaconda
到anaconda安装包所在的文件,用终端打开:
bash Anaconda2-4.1.1-Linux-x86_64.sh #输入你下载的anaconda包名

添加路径:

sudo vi /etc/ld.so.conf

按i开始编辑:
/home/#你的用户名#/anaconda2/lib
按esc键,输入:wq,回车
注意这一步,先去查看你的真实路径是什么,再去编辑
方法2:安装原生Python
这种方法速度慢,遇到的错误多,不是很推荐
sudo apt-get install python-pip
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
在解压出来的caffe-master文件夹中找到python文件夹,在终端打开
for req in $(cat requirements.txt); do pip install $req; done
如果上面的命令速度太慢,则
** 换成清华大学pip资源下载
for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
** 或者在下载时,直接按ctrl+c取消下载,根据下载时提供的资源名自行下载,大多为.whl文件,百度如何安装即可
若有错误就多安几次,直到全都安上
7)编译caffe:
在终端中打开caffe-master文件,输入
sudo cp Makefile.config.example Makefile.config
gedit 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 := 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

# 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 ?= @

保存退出
开始编译caffe:
make all -j4
make test -j4
make runtest
至此,caffe编译完毕。

我们用mnist数据集测试一下,在终端打开caffe-master文件夹:
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/lenet_train_test.prototxtmodel

结果如下:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值