Win10 Andaconda环境 Theano 1.0.4版本下安装以及GPU的配置

首先安装theano是参考了这篇文章

win10系统 anaconda环境 安装theano绝对成功

即新建环境之后进行一顿操作

conda create -n theano python=3.5
conda create -n theano python=2.7
activate theano
conda install mingw libpython
conda install mkl
conda install nose
conda install theano pygpu
conda install mkl-service
python 

然后测试theano是否安装成功

import numpy
import theano.tensor as T
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
#若有以下结果,则说明安装成功
f(2, 3)#array(5.0)
numpy.allclose(f(16.3, 12.1), 28.4)#True

然后开始配置GPU,现在很多博客都会要求用户在一顿操作安装cuda和cudnn之后在。theanorc.txt文件中输入下面图片这些东西

图片截图于:Win10环境下安装theano并配置GPU详细教程

但是目前新版本的theano不需要这样的配置

按照官网上的说法,只需要在theanorc.txt中写

[global]
device = cuda
floatX = float32
allow_input_downcast=True

然后这个theanorc.txt文件放在

C:\User\你的用户名 这个文件夹中

像我这样

就可以了

然后运行以下测试代码:(当然也是从官网直接能找到的)

from theano import function, config, shared, tensor
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([], tensor.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, tensor.Elemwise) and
			  ('Gpu' not in type(x.op).__name__)
			  for x in f.maker.fgraph.toposort()]):
	print('Used the cpu')
else:
	print('Used the gpu')

 

如果可以在输出信息中看到自己显卡的名字,就算是成功了

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值