测试theano是提示使用CPU而不是gpu问题
来源:互联网 发布:个人隐私 知乎 编辑:程序博客网 时间:2024/06/05 21:16
测试theano是提示使用CPU而不是gpu问题:
cuda 和theano配置完成后,进行theano测试
为了检查你的GPU是否启用了,可以剪切下面的代码然后保存成一个Python文件(我命名为test_gpu1.py),运行看看。
- 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 xrange(iters):
- r = f()
- t1 = time.time()
- print 'Looping %d times took' % iters, t1 - t0, 'seconds'
- print 'Result is', 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'
直接在终端命令行敲:python test_gpu1.py
运行结束后提示显示的是Used the cpu!!(后来经过查找资料这种情况其实是由于theano的默认配置中不是使用GPU而是CPU)
反复在根目录下添加环境变量也没能解决。最后解决方法是在命令行上指定模式 并运行test_gpu1.py:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_gpu1.py
同理如果指定用CPU的话就在终端上敲:
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_gpu1.py
在theano 的官网教程中,配置环境变量有两种方法:
第一种方法是THEANO_FLAGS方法(即上面使用的)
第二种方法是在根目录(home/hf(用户名为hf))下建立.theanorc文件并添加例如类似下面:
[global]
floatX=float32
device=gpu0
[lib]
cnmem=1
但我用第二种方法没能成功,第一种方法确实可行!
****第二种方法没能成功 的原因是:当时我在控制台用的是root身份,而.theanorc 所创建的根目录为home/hf(这是hf用户的根目录!!)所以我在root的根目录(cd $HOME)下创建.theano 就好了!!!
- 测试theano是提示使用CPU而不是gpu问题
- Theano和Tensorflow多GPU使用问题
- 使用gpu加速theano
- 测试Theano使用GPU并行计算,以验证环境搭建是否成功
- GPU与CPU对比测试
- theano GPU
- 使用GPU和Theano加速深度学习
- 使用GPU和Theano加速深度学习
- ubuntu下让theano使用GPU
- 配置使用GPU加速的Theano环境
- Step by Step Ubuntu下GPU测试Theano
- 【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)
- win7 pycharm下 安装使用GPU 的theano
- 在ubuntu14.10上安装theano并且使用GPU加速
- Theano+GPU配置
- theano GPU install
- win7 安装theano+gpu
- Theano运行GPU配置
- Python——序列迭代
- LIS LCS n^2和nlogn解法 以及LCIS
- 关于python的url处理
- 磁盘原理与文件系统
- GSM
- 测试theano是提示使用CPU而不是gpu问题
- [剑指offer学习心得]之:二叉树的深度
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- maven项目配置
- DP(最大子段和) 最大子矩阵 poj_1050
- JQuery通过radio,select改变隐藏显示div
- Expression Add Operators
- Java基础 hashCode() 和equals() 区别和作用
- 微信小程序例子——下拉列表