### Theano
2015-08-23 19:59
295 查看
Theano.
#@author: gr #@date: 2014-07-02 #@email: forgerui@gmail.com
一、安装Theano
ubuntu下安装相对简单。安装依赖:
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git libatlas3gf-base libatlas-dev
安装theano:
sudo pip install Theano
测试安装是否成功:
$ python >>> import theano >>> theano.test()
二、用GPU加速
神经网络需要大量的计算,利用cuda可以进行有效的加速。可以使用如下脚本进行测试gpu, 保存为check1.py:
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'
运行时分别使用cpu、gpu测试:
$ THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python check1.py [Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)] Looping 1000 times took 3.06635117531 seconds Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761 1.62323284] Used the cpu $ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py Using gpu device 0: GeForce GTX 580 [GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)] Looping 1000 times took 0.638810873032 seconds Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296] Used the gpu
我在本机上测试,平均速度要快5倍左右。
三、实例分析LeNet
LeNet是Y. LeCun设计的一种卷积神经网络。我们可以使用这个深度学习的教程,代码在GitHub上。Reference
http://deeplearning.net/software/theano/install_ubuntu.htmlhttp://deeplearning.net/software/theano/tutorial/using_gpu.html
http://deeplearning.net/tutorial/contents.html
http://deeplearning.net/tutorial/lenet.html
相关文章推荐
- 帮助命令
- 创建虚拟机生成虚拟机全程日志打印输出流程详解(openstack开发必备)
- Oracle与Sql Server复制表结构和数据
- 条件覆盖,路径覆盖,语句覆盖,分支覆盖解释
- linux常用命令
- 黑马程序员—IOS加强视频—分类
- linux常用命令.txt
- 820 - Internet Bandwidth(最大流模板题)
- linux常用命令.txt
- linux关机重启命令.txt
- InterlockedIncrement内部是如何实现的?
- hdu5366(DP)
- Spring配置文件解析--bean属性
- ### Python Learning
- linux链接命令.txt
- 目录处理命令
- shell-字符截取命令sed
- Java修饰符关键词大全
- 前端开发必须知道的JS(一) 原型和继承(转)
- Spring学习之Aop的基本概念