### 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调用这些变量时,遇到一次就要调用一次,这样就会花费大量时间在数据 ...
随机推荐
- PCb过孔大小设置 / 丝印层字符尺寸设置
PCb过孔大小一般设置为:内孔(孔尺寸)0.30(12mil),外壳(直径)0.6(24mil) 常用过孔设置: 内径: 15mil(0.381mm) 30mil(0.762mm) 外径: 20mi ...
- unable to load default svn client myeclipse SVN安装,wen7 64位安装SVN
在安装完后连接svn时出现unable to load default svn client的错误提示,百度知道是版本不对,我安装的是1.8的版本,插件按成1.6的了,只需下载1.8插件安装就行了 安 ...
- Hibernate映射文件简单配置
<?xml version="1.0" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibe ...
- Java中的二维数组
Java 中的二维数组 所谓二维数组,可以简单的理解为是一种"特殊"的一维数组,它的每个数组空间中保存的是一个一维数组. 那么如何使用二维数组呢,步骤如下: 1. 声明数组并分配空 ...
- 获取WMI硬件清单
WMI服务能够报告详细的硬件信息.通常,每个硬件都来自它们自己的WMI代理类.但是要找出这些硬件类的名字是不容易. 所有硬件类都在同一个WMI根下面,你可以在根类查询所有的硬件: Get-WmiObj ...
- mysql学习--mysql必知必会1
例如以下为mysql必知必会第九章開始: 正則表達式用于匹配特殊的字符集合.mysql通过where子句对正則表達式提供初步的支持. keywordregexp用来表示后面跟的东西作为正則表達式 ...
- 产生不重复的随机数TGUID
uses ActiveX; procedure TForm1.BtnNewClick(Sender: TObject);var ID: TGUID; S: string;begin if CoC ...
- pomelo 开发环境搭建
开发前提条件: Windows系统,请确保你的Windows系统包括源代码编译工具.Node.js的源代码主要由C++代码和JavaScript代码构成,可是却用gyp工具来做源代码的项目管理,该工 ...
- com.service.impl
package com.service.impl; import java.util.ArrayList; import java.util.LinkedHashMap; import java.ut ...
- java_Cookie添加和删除
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...