我很感动
经历了一堆安装theano的挫折
安装theano
步骤:
1. 在anaconda的的anaconda prompt下进入你的安装环境,输入以下指令:
conda install numpy scipy mkl-service libpython m2w64-toolchain
这里另外说一下网上基本上遍布的安装theano方法:
使用
conda install mingw libpython
来安装mingw,但我想说这种方法安装的mingw是32位的,所以如果使用这种方法来安装,运行theano的时候会出现错误
下面还有一小段错误~忘截图了,大概意思是can"t compile 64bit?...反正就是说编译不了64位
所以这就要求你需要安装64位的mingw,第一条指令可以解决这个问题。
2.安装theano
pip install theano
3. 添加环境变量path
添加:
怎么添加环境变量就不说了,网上很多教程。
4.编写一个txt
在C:/users/dell目录下添加一个txt
在txt文件里加入以下内容:
-I后面加的是mingw的安装目录
经历这些步骤,theano差不多就算安装完了,可以测试一下:
import numpy
import theano.tensor as T
import sys
from theano import function
x = T.dscalar('x')
y = T.dscalar('y')
z = x + y
f = function([x, y], z)
print f(2,3)
# print theano.__path__
# print sys.path
出来5就算对了
对vscode的配置
点击python
选第三个,configure python language based settings
修改user settings
修改python.pythonpath
theano gpu
gpu测试
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')