Linux下安装theano

本文详细介绍如何在Ubuntu系统上安装Theano,并设置其使用GPU进行运算加速的方法。包括安装Python依赖包、调整Theano配置文件及通过示例代码验证GPU是否被正确启用。
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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值