Linux下安装theano

0.install theano                                                                                                                                                        
 1.sudo apt-get install python-pip
 2.sudo apt-get install python-dev python-nose g++ libopenblas-dev git 
 3.sudo pip install theano
(if step 3 not work, change source url of pip(eg. douban),link url is  
http://ju.outofmemory.cn/entry/108631
)
 
1.user theano with gpu 
 
在用户的~目录下新建配置文件sudo vi ~/.theanorc
添加如下内容:
[global]
floatX=float32
device=gpu
 
新建文件test.py,将以下code贴到该文件中。
  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 %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')
 
运行python test.py
 
result中显示use gpu就成功了。^_^


reference link:http://www.myexception.cn/cuda/2017261.html 

你可能感兴趣的:(Linux,DeepLearning)