win7下Anaconda 的theano安装记录

    卤煮已经在windows平台安装了niuzhiheng&&happynear的caffe,用起来甚爽,真心比Linux直观,谁叫咱们用了这么久的windows呢。当然ubuntu用起来也是很爽的……跑题了又……

    打算重新过一遍深度学习的代码,熟悉下算法so ,不得不提的http://deeplearning.net/tutorial/确实是一个比较好的撸代码的选择,于是乎我需要重新安装一下这万人景仰的theano,由于已经安装过了Anaconda这个python包,当然是2.7的,so,针对官方的安装办法需要按照自己的情况进行选择。于是跑到http://deeplearning.net/software/theano/撸一下user guide。发现什么cuda,numpy各种云云,已经安装好了……于是我的安装步骤分为以下:

1 升级Anaconda

跳过,发现一句cmd下的命令

conda install mingw libpython

于是执行,发现它帮我安装了mingw,并且升级了python的一众工具包。


2 下载安装并配置 theano 0.7

    1〉下载见https://pypi.python.org/pypi/Theano

     2〉进入下载后解压的目录 然后执行 python setup.py install

     3> 之后同样在该目录下

python setup.py develop

至此,强大的theano已经安装完毕,可以打开Anaconda的 spyder编辑器粘贴下面代码

import numpy as np
import time
import theano
A = np.random.rand(1000,10000).astype(theano.config.floatX)
B = np.random.rand(10000,1000).astype(theano.config.floatX)
np_start = time.time()
AB = A.dot(B)
np_end = time.time()
X,Y = theano.tensor.matrices('XY')
mf = theano.function([X,Y],X.dot(Y))
t_start = time.time()
tAB = mf(A,B)
t_end = time.time()
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
                                           np_end-np_start, t_end-t_start))
print("Result difference: %f" % (np.abs(AB-tAB).max(), ))
正常情况下 console会输出

NP time: 0.129000[s], theano time: 0.092000[s] (times should be close when run on CPU!)
Result difference: 0.000000

3 安装cuda支持并配置theano的gpu mode

看到支持GPU,忍不住装下,cuda已经装好,不在复述。

这里主要讲下 如何配置theano

闲话不说,直接在你登陆用户的目录下新建文件

.theanorc.txt注意这里不需要文件名

粘贴以下内容到新建的文件下,注意里边不需要空格。 

[global]
openmp=False
device=gpu
floatX=float32
allow_input_downcast=True
[blas]
ldflags =
[gcc]
cxxflags=-IE:\Anaconda2\pkgs\mingw-4.7-1\MinGW\x86_64-w64-mingw32\include  #你的 MinG目录
[nvcc]
flags=-LE:\Anaconda2\libs #你的python目录
compiler_bindir=E:\vstudio12\VC\bin#你的vs.net 的vc目录
fastmath=True
flags=-arch=sm_50#按照gpu的能力来设定nvcc里边可以测到自己的gpu支持什么

搞定了之后,测试,粘贴如下代码

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 range(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')	
配置正常情况下会输出:
Looping 1000 times took 1.221000 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu 至此,你的theano已经安装完毕,可以开始你的deep learning的旅程了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值