首页 分享 ubuntu16.04 Anaconda虚拟环境配置theano gpu版本

ubuntu16.04 Anaconda虚拟环境配置theano gpu版本

来源:萌宠菠菠乐园 时间:2026-02-23 20:02

最新推荐文章于 2020-06-30 15:05:02 发布

原创 于 2018-08-04 16:25:32 发布 · 1.1k 阅读

· 0

· 1 ·

CC 4.0 BY-SA版权

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

配置过程主要分为下面几个步骤
1. 安装theano1.0.2
2. 安装Lasagne 0.2 dev1
3. 安装OpenCV 3.4
4. 安装cuda和cudnn
5. 配置theanorc文件
下面展开列出详细的安装过程,默认已安装显卡驱动

安装theano1.0.2、lasagne0.2、Opencv

创建并激活环境,然后使用conda安装

#python使用2.7,环境名为theano conda create -n theano python=2.7 #激活环境 source activate theano #安装theano和lasagne #下面两行命令会安装最新版本达theano和lasagne pip install --upgrade https://github.com/Theano/Theano/archive/master.zip pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip #安装Opencv pip install opencv-python

12345678910111213

安装cuda和cudnn

下面这篇文章写得很详细,注意cudnn要求5.1版本,cuda我配的是8.0
https://blog.csdn.net/allenlzcoder/article/details/78702279

配置theanorc文件

sudo gedit ~/.theanorc1

在里面写入

[global] device=gpu floatX=float32 root=/usr/local/cuda-8.0 [nvcc] fastmath = True [blas] ldflags = -lopenblas [cuda] root = /usr/local/cuda-8.0 #下面是内存分配,可以注释掉 [lib] cnmem =3000

12345678910111213

测试

测试文件

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'

12345678910111213141516171819202122

输出结果

(theano) cyc@cyc-Inspiron-5577:~$ python a.py WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL: https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29 Using gpu device 0: GeForce GTX 1050 (CNMeM is disabled, cuDNN 5110) [GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)] Looping 1000 times took 0.335947036743 seconds Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296] Used the gpu

1234567891011

配置完成,可以用啦

相关知识

win10+GPU+tensorflow安装配置 过程 的吐血总结
在windows笔记本中安装tensorflow1.13.2版本的gpu环境
无法在anaconda创建新环境问题
PyTorch GPU利用率为0%(很低)
手把手教你租用服务器以及使用Pycharm远程连接服务器训练模型
04训练——基于YOLO V8的自定义数据集训练——使用免费在线GPU资源
肆十二/YOLOV5
Pytorch使用cuda后,任务管理器GPU的利用率还是为0?
ubuntu16.04安装opencv3.4.1时出现: libgtk2.0
python和anaconda的区别

网址: ubuntu16.04 Anaconda虚拟环境配置theano gpu版本 https://www.mcbbbk.com/newsview1352296.html

所属分类:萌宠日常
上一篇: 丹江口市商务局:“信易+家政服务
下一篇: 关注养宠家庭|骊住精细化打造“人

推荐分享