首先去官网上查看适合你GPU的驱动
(http://www.nvidia.com/Download/index.aspx?lang=en-us)
[python] view plain copy
执行完上述后,重启(reboot)。
重启后输入
[python] view plain copy
如果出现了你的GPU列表,则说明驱动安装成功了。另外也可以通过,或者输入
[python] view plain copy
出现
https://developer.nvidia.com/cuda-downloads
在cuda所在目录打开terminal依次输入以下指令:
[python] view plain copy
ubuntu的gcc编译器是5.4.0,然而cuda8.0不支持5.0以上的编译器,因此需要降级,把编译器版本降到4.9:
在terminal中执行:
[python] view plain copy
配置cuda8.0之后主要加上的一个环境变量声明,在文件~/.bashrc之后加上
[python] view plain copy
然后设置环境变量和动态链接库,在命令行输入
[python] view plain copy
在打开的文件里面加上(注意等号两边不能有空格)
[python] view plain copy
保存之后,创建链接文件
[python] view plain copy
在打开的文件中添加如下语句:
[python] view plain copy
保存退出执行命令行:
[python] view plain copy
使链接立即生效。
命令行输入(注意cuda-8.0是要相对应自己的cuda版本)
[python] view plain copy
返回GPU的信息则表示配置成功
上官网下载对应的cudnn
https://developer.nvidia.com/cudnn
下载完cudnn后,命令行输入文件所在的文件夹 (ubuntu为本机用户名)
[python] view plain copy
cd进入cudnn5.1解压之后的include目录,在命令行进行如下操作:
[python] view plain copy
再cd进入lib64目录下的动态文件进行复制和链接:(5.1.5为对应版本具体可修改)
[python] view plain copy
从官网上下载opencv3.1.0
http://OpenCV.org/downloads.html
并将其解压到你要安装的位置,(下载的位置还是在home/ubuntu、Downloads文件夹下)
首先安装Ubuntu系统需要的依赖项,虽然我也不知道有些依赖项是干啥的,但是只管装就行,也不会占据很多空间的。
[python] view plain copy
然后安装opencv需要的一些依赖项,一些文件编码解码之类的东东。
[python] view plain copy
在终端中cd到opencv文件夹下(解压的那个文件夹),然后
[python] view plain copy
cmake成功后,会出现如下结果,提示配置和生成成功:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ise/software/opencv-3.1.0/build
由于CUDA 8.0不支持OpenCV的 GraphCut 算法,可能出现以下错误:
/home/usrname/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp:120:54: error: 'NppiGraphcutState' has not been declared
typedef NppStatus (*init_func_t)(NppiSize oSize, NppiGraphcutState** ppStat
^
/home/usrname/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp:135:18: error: 'NppiGraphcutState' does not name a type
operator NppiGraphcutState*()
^
/home/usrname/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp:141:9: error: 'NppiGraphcutState' does not name a type
NppiGraphcutState* pState;
.......
进入opencv-3.1.0/modules/cudalegacy/src/目录,修改graphcuts.cpp文件,将:
#include "precomp.hpp"
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
改为
#include "precomp.hpp"
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
然后make编译就可以了
[python] view plain copy
上面是将opencv编译成功,但是并没有安装到我们的系统中,有很多的设置都没有写入到系统中,因此还要进行install。
[python] view plain copy
[python] view plain copy
这里感谢这位朋友的提醒
然后按照提示安装就可以了。 使用checkinstall的目的是为了更好的管理我安装的opencv,因为opencv的安装很麻烦,卸载更麻烦,其安装的时候修改了一大堆的文件,当我想使用别的版本的opencv时,将当前版本的opencv卸载就是一件头疼的事情,因此需要使用checkinstall来管理我的安装。执行了checkinstall后,会在build文件下生成一个以backup开头的.tgz的备份文件和一个以build开头的.deb安装文件,当你想卸载当前的opencv时,直接执行dpkg -r build即可。
切换编译器
选择g++ 5.0以上的对应编号
[python] view plain copy
[python] view plain copy
安装依赖库
[python] view plain copy
# General Dependencies
[python] view plain copy
# BLAS
[python] view plain copy
# Remaining Dependencies
[python] view plain copy
编译 Caffe,cd到要安装caffe的位置
[python] view plain copy
修改Makefile.config:
[python] view plain copy
对打开的文件编辑
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# Uncomment if you're using OpenCV 3 如果用的是opencv3版本
OPENCV_VERSION := 3
# Uncomment to support layers written in Python (will link against python libs)
WITH_PYTHON_LAYER := 1
在问件里面添加文本由于hdf5库目录更改,所以需要单独添加:
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/hdf5/serial/
打开makefile文件
[python] view plain copy
将
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
编辑/usr/local/cuda/include/host_config.h,将其中的第115行注释掉:
[python] view plain copy
将
#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
改为
//#error-- unsupported GNU version! gcc versions later than 4.9 are not supported!
之后编辑即可
[python] view plain copy
为了更好地使用pycaffe ,建议安装:
[python] view plain copy
到这里Caffe开发环境就配置好了!
可以测试一下,输出AlexNet的时间测试结果:
[python] view plain copy
1、直接输入命令:
[python] view plain copy
2、配置参数文件:.theanorc
[python] view plain copy
对打开的文件进行编辑
[global]
floatX=float32
device=gpu
base_compiledir=~/external/.theano/
allow_gc=False
warn_float64=warn
[mode]=FAST_RUN
[nvcc]
fastmath=True
[cuda]
root=/usr/local/cuda
3、运行测试例子:
[python] view plain copy
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
可以看到结果:
/usr/bin/python2.7 /home/hjimce/PycharmProjects/untitled/.idea/temp.py
Using gpu device 0: GeForce GTX 960 (CNMeM is disabled, cuDNN not available)
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.302778 seconds
Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761
1.62323296]
Used the gpu
说明安装成功
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md
先安装anaconda
https://repo.continuum.io/archive/Anaconda2-4.2.0-Windows-x86_64.exe
上面的地址下载 该包默认在downloads里面
[python] view plain copy
配置环境变量
[python] view plain copy
末尾添上,我是一路yes下来,所以安在了root下,你可以自己选路径,这时候的环境变量要改
export PATH=/root/anaconda2/bin:$PATH
重启
打开终端
[python] view plain copy
安装成功
2、创建conda环境 名字叫tensorflow
[python] view plain copy
#下面这句话只能下载给CPU用的tensorflow
[python] view plain copy
利用pip来下载给GPU用的tensorflow
[python] view plain copy
下载安装
[python] view plain copy
安装IPython
[python] view plain copy
关掉该环境
[python] view plain copy
测试安装是否正确
[python] view plain copy
输入
[python] view plain copy
OK
问题:找不到Python.h
解决:给anaconda添加环境变量
[python] view plain copy
添加
export PATH=/root/anaconda2/bin:$PATH
export PYTHONPATH=/path/to/caffe/python:$PATH
修改Makefile.config
在终端输入
[python] view plain copy
[python] view plain copy
在INCLUDE_DIRS 和LIBRARY_DIRS后面添上
/root/anaconda2/include/python2.7
启用
ANACONDA_HOME := $(HOME)/anaconda2
PYTHON_ INCLUDE =$(ANACONDA_HOME)/include\
,把前面的#去掉,那三行都去掉#,并在注释上面,
注释这两句PYTHON_INCLUDE := /usr/include/python2.7\
/usr/lib/python2.7…………..
如果编译的时候发现有错,回来改完之后又得重新编译一遍pycaffe,于是出现如下错误
make: Nothing to be done for 'pycaffe'
则在终端输入:
[python] view plain copy
修改完后再
[python] view plain copy
编译完后,显示
然后 cd python进入该目录
[python] view plain copy
若此时提示错误:
Traceback (most recent call last)
File
ImportError: /home/../anaconda2/lib/python2.7/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: versionGLIBCXX_3.4.21' not found
解决:
https://github.com/BVLC/caffe/issues/4953
https://gitter.im/BVLC/caffe/archives/2015/08/20
[python] view plain copy
本文链接:http://task.lmcjl.com/news/3252.html