theano安装步骤:
- Python的安装及一系列的包
- Microsoft Visual Studio
- CUDA
- pycuda
- theano
1. Python的安装一及一系列的包
Python建议安装Anaconda,这个打包集成科学计算的包,像什么numpy、scipy等等。
不过国内的下载速度感人,建议上ss。这里我用的是最新的版本
2.Microsoft Visual Studio安装
建议安装vs2013版本的,这里的我安装的是vs2015。安装社区版的就行。
3.CUDA安装
注意一定要选对平台,然后傻瓜式安装
4.pycuda安装
我们先要安装
Boost.Python 地址:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
这里还要安装pytools,直接用pip安装即可
然后在安装pycuda
5.theano安装
先用conda安装mingw、libpython
打开cmd使用命令:conda install mingw libpython
等安装完后,使用命令pip install theano
然后在你的user文件下创建.theanorc.txt这个文件。注意前面有个.
[global]
floatX = float32
device = gpu
[nvcc]
flags=-LD:/plang/Anaconda3/libs
compiler_bindir=C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin
这是我的配置文件看着改就行。
然后打开cmd输入Python
看import theano能运行不能
我的出了一个错误:Failed to compile cuda_ndarray.cu: 'utf-8' codec ca
这时候你可以去这个文章上看一看安装python3 keras 出现的错误
然后就可以运行一下这个测试代码看行不行了
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')
如出现这个,恭喜你安装成功了