基本上按照官网来就行:html
先是python
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
再是linux
sudo pip install Theano
(这一步骤里,若是你默认是python3,则要改成pip-2.7)git
测试下:dom
Test the newly installed packagesoop
python -c "import numpy; numpy.test()" 约~30s python -c "import scipy; scipy.test()" 约~1m python -c "import theano; theano.test()" 约~30m
Speed test Theano/BLAS测试
python `python -c "import os, theano; print os.path.dirname(theano.__file__)"`/misc/check_blas.py
测试成功,基本上就能用了。spa
如下是GPU设置:.net
检查本身的电脑是否有cuda支持的GPUhtm
lspci | grep -i nvidia
通常获得相似下面的结果
01:00.0 VGA compatible controller: NVIDIA ……
另外,也可用
lspci | grep -i vga
显示全部显卡,用
lspci -v -s 01:00.0
显示特定显卡详细信息。
若是支持,那么安装就好了:
sudo apt-get install nvidia-current sudo apt-get install nvidia-cuda-toolkit
而后主要是设置参数,让优先使用GPU
参见http://deeplearning.net/software/theano/install.html里Using the GPU一节。
主要有两种方法,一种设置THEANO_FLAGS,一种编辑.theanorc文件,之后者为例,
在$home目录(用户主目录,通常是/home/用户名)下建立“ .theanorc”文件,编辑为
[global] device = gpu floatX = float32 [cuda] root = /usr/lib/nvidia-cuda-toolkit //cuda目录一项设置为本身的cuda安装目录便可(内含bin,lib,include子文件夹)
注意,这个文件你建立了,通常会变为不可见,可用"ls -a"命令列出全部文件从而能够看到,能够用gedit编辑。
此外,还要设置cuda的lib子文件夹(64位下可能还要设置lib64子文件夹)位置到环境变量$LD_LIBRARY_PATH,参见http://blog.csdn.net/xsc_c/article/details/23470565(这篇博客cuda的几个入门文章也很不错)。或者这篇http://www.linuxidc.com/Linux/2012-04/58913.htm 。以设置/etc/profile为例,在其中添加
export PATH=$PATH:/usr/lib/nvidia-cuda-toolkit/bin %这句不加通常也行 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia-cuda-toolkit/lib
测试例子在http://deeplearning.net/software/theano/tutorial/using_gpu.html#using-gpu
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 xrange(iters): r = f() t1 = time.time() print 'Looping %d times took' % iters, t1 - t0, 'seconds' print 'Result is', 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'
若是执行时有相似“unable to get the number of gpus avaliable”的错误,用sudo执行便可。
若是有权限问题,如"Permission denied"相似错误,删除主目录下的文件夹".theano"或者其子文件夹,
好比,在个人电脑上,存在这样的文件夹"/home/用户名/.theano/compiledir_Linux-3.16--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/",将其删除便可.
注意,".theano"是隐藏的文件夹,用"ls -a"命令能够看到.