win10下基于Theano框架的Lasagne平台搭建(CPU版)

一、系统配置

1、操作系统:win10 1803
2、处理器:Intel® Core™ i7-8700 CPU @ 3.70GHz
3、显卡:NVIDIA GeForce GTX 1070Ti
4、内存:16GB
5、已安装:CUDA+cudnn,anaconda4.6.14

二、安装

安装Theano和Lasagne
1、GitHub教程:https://github.com/Lasagne/Lasagne
教程中README内容很多,关键的只有两点。(这个GitHub项目文件不需要git或下载到本地)
在此之前,我们先使用anaconda创建一个Theano的虚拟环境

conda create -n xxx python==3.5    # lasagne官网提示python版本3.4<版本<3.6
activate xxx   #进入虚拟环境

接下来开始安装Theano和Lasagne,分开执行

pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt
pip install https://github.com/Lasagne/Lasagne/archive/master.zip

此时,基本框架已经安装完成。官方给出了测试的代码,如果使用CPU,会打印出“Used the cpu”,如果使用GPU,会打印出“Used the gpu”

#!/user/bin/env python
# _*_coding:utf-8 _*_

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')

这时就会报出一些错误,由于是我之前遇到的问题,当时并没有截图。所以我直接写上,

WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu0 is not available
AssertionError: AbstractConv2d Theano optimization failed: there is no implementation available supporting the requested options. Did you exclude both "conv_dnn" and "conv_gemm" from the optimizer? If on GPU, is cuDNN available and does the GPU support it? If on CPU, do you have a BLAS library installed Theano can link against?

现在我的问题解决了,但还是显示“g++ not detected!”,不过能够运行。找网上的方法说安装mingw可以解决,但是我的并没有用。不过还是装了。不确定有没有用啊。

conda install mingw libpython

接下来就是在C:\Users\“你的用户名”目录下新建一个名为.theanorc.txt文件,我里面的内容为

[cxx]
flags=C:\Users\“你的用户名”\Anaconda3\envs\theano\MinGW\bin
[global]
floatX = float32
device = cpu
optimizer = None
[blas]
ldflags = -lopenblas

说实话,不确定哪一条起的作用,但是CPU确实是能运行了。我按照网上的做法尝试GPU,仍然没有成功。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值