### Theano
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.html
- http://deeplearning.net/software/theano/tutorial/using_gpu.html
- http://deeplearning.net/tutorial/contents.html
- http://deeplearning.net/tutorial/lenet.html
### Theano的更多相关文章
- Deconvolution Using Theano
Transposed Convolution, 也叫Fractional Strided Convolution, 或者流行的(错误)称谓: 反卷积, Deconvolution. 定义请参考tuto ...
- Theano printing
Theano printing To visualize the internal relation graph of theano variables. Installing conda insta ...
- Theano Graph Structure
Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...
- Theano Inplace
Theano Inplace inplace Computation computation that destroy their inputs as a side-effect. Example i ...
- broadcasting Theano vs. Numpy
broadcasting Theano vs. Numpy broadcast mechanism allows a scalar may be added to a matrix, a vector ...
- theano scan optimization
selected from Theano Doc Optimizing Scan performance Minimizing Scan Usage performan as much of the ...
- theano sparse_block_dot
theano 中的一个函数 sparse_block_dot; Function: for b in range(batch_size): for j in range(o.shape[1]): fo ...
- ubuntu系统theano和keras的安装
说明:系统是unbuntu14.04LTS,32位的操作系统,以前安装了python3.4,现在想要安装theano和keras.步骤如下: 1,安装pip sudo apt-get install ...
- theano学习
import numpy import theano.tensor as T from theano import function x = T.dscalar('x') y = T.dscalar( ...
- Theano 学习笔记(一)
Theano 学习笔记(一) theano 为什么要定义共享变量? 定义共享变量的原因在于GPU的使用,如果不定义共享的话,那么当GPU调用这些变量时,遇到一次就要调用一次,这样就会花费大量时间在数据 ...
随机推荐
- [iOS基础控件 - 1] UI概念
A. UIView 1.概念 属于UIKit框架 屏幕上能看得见摸得着的东西就是UIView,比如屏幕上的按钮.文字.图片 翻译为:视图/控件/组件 UIBut ...
- 【Stage3D学习笔记续】真正的3D世界(五):粒子特效
先看效果,按下空格键添加粒子特效: 一般而言粒子特效的实现都是比较复杂的,且不说实现粒子特效的编码和设计,光是编写一个粒子编辑器就不是简单的一件事,但是作者使用了很取巧的方式来完成,我们接下来深入代码 ...
- Oracle 中利用闪回查询确定某表在某时间点之后的修改内容,并恢复至该时间点
Oracle 中利用闪回查询确定某表在某时间点之后的修改内容: 1.查看 DELETE 及 UPDATE 操作修改的数据: SQL> SELECT * FROM tab AS OF TIMEST ...
- redis优化优秀文选
Redis是一个单线程的内存数据库.下载地址如下:http://download.redis.io/releases/redis-2.8.11.tar.gz在Redis的src目录运行make命令,然 ...
- UITextfield设置Placeholder颜色 控件 内边距、自适应高度
//创建UITextField对象 UITextField * tf=[[UITextField alloc]init]; //设置Placeholder颜色 [text setAttribut ...
- 使用纯代码定义UICollectionView和自定义UICollectionViewCell
1.自定义UICollectionView 2.实现<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollec ...
- poj 1147 Binary codes
Binary codes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5647 Accepted: 2201 Desc ...
- iOS开发——屏幕适配篇&autoResizing autoLayout和sizeClass
autoResizing autoLayout和sizeClass,VFL,Masonry详解 1. autoResizing autoresizing是苹果早期的ui布局适配的解决办法,iOS6之前 ...
- pomelo 初始化配置...
在创建app的时候会初始化master和server以及log配置.. /** * Initialize application configuration. */ module.exports.de ...
- 23、从头学Android之ContentProvider .
http://blog.csdn.net/jiahui524/article/details/7016430 应用场景: 在Android官方指出的Android的数据存储方式总共有五种,分别是:Sh ...