theano在windows下的安装

来源:互联网 发布:100元的智能手机淘宝 编辑:程序博客网 时间:2024/06/01 10:05

theano安装步骤:

  1. Python的安装及一系列的包
  2. Microsoft Visual Studio
  3.  CUDA
  4. pycuda
  5. theano

1. Python的安装一及一系列的包

Python建议安装Anaconda,这个打包集成科学计算的包,像什么numpy、scipy等等。
地址:https://www.continuum.io/downloads/
不过国内的下载速度感人,建议上ss。这里我用的是最新的版本

2.Microsoft Visual Studio安装

建议安装vs2013版本的,这里的我安装的是vs2015。安装社区版的就行。

3.CUDA安装

地址:https://developer.nvidia.com/cuda-downloads
注意一定要选对平台,然后傻瓜式安装

4.pycuda安装

我们先要安装 
Boost.Python 地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/
这里还要安装pytools,直接用pip安装即可
然后在安装pycuda
地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda

5.theano安装

用conda安装mingw、libpython
打开cmd使用命令:conda install mingw libpython
等安装完后,使用命令pip install theano
然后在你的user文件下创建.theanorc.txt这个文件。注意前面有个.
[global]floatX = float32device = gpu[nvcc]flags=-LD:/plang/Anaconda3/libscompiler_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, sandboximport theano.tensor as Timport numpyimport timevlen = 10 * 30 * 768  # 10 x #cores x # threads per coreiters = 1000rng = 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')

如出现这个,恭喜你安装成功了



0 0
原创粉丝点击