theano版本依赖的坑

theano版本依赖的坑

  • ubuntu+theano的安装教程
  • theano后端修改
  • theano版本更新
  • 参考网址

ubuntu+theano的安装教程

https://blog.csdn.net/hczhcz0905/article/details/80424023
https://blog.csdn.net/Xujian0000abcd/article/details/51352707
pygpu安装命令如下:

        git clone https://github.com/Theano/libgpuarray.git
        cd libgpuarray
        mkdir Build
        cd Build
        cmake .. -DCMAKE_BUILD_TYPE=Release
        make 
        make install
        cd ..
        python setup.py build 
        python setup.py install    
        sudo ldconfig

theano后端修改

theano 0.9以上版本,使用gpu新后端,device=gpu或cpu或cuda(新后端) ,需要修改的话,按住ctrl+alt+t进入命令行,输入

sudo gedit ~/.theanorc #修改device

配置完环境后,可以用下面的代码测试一下,使用的是gpu还是cpu:

# -*- coding: utf-8 -*-
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'  

备注:有测试过pygpu=0.6.5theano=0.9.0 或者pygpu=0.7.5theano=1.0.0 OK.
注意:我在测试是gpu还是cpu时遇到了一个问题,我安装的theano==1.0.4device=cuda,但是我测试时一直提示的是我使用的是cpu,通过各种检索,找到了一个答案:
https://github.com/Theano/Theano/issues/6065

The script you are using to test does not seem to detect GPU usage correctly.
In fact, since it prints GpuElemwise{exp,no_inplace}((float32, vector)>), you can be sure that it actually is using the GPU.
Are you using the latest version of the script at http://deeplearning.net/software/theano/tutorial/using_gpu.html#testing-theano-with-gpu ?

之后我从http://deeplearning.net/software/theano/tutorial/using_gpu.html#testing-theano-with-gpu 网址上拷贝了对应的代码重新运行了一下,终于成功…
theano版本依赖的坑_第1张图片

theano版本更新

theano 0.9 以上版本运行时会有提示:

C:\Program Files\Anaconda2\lib\site-packages\keras\backend\theano_backend.py:1500: UserWarning: DEPRECATION: the 'ds' parameter is not going to exist anymore as it is going to be replaced by the parameter 'ws'.
  mode='max')
C:\Program Files\Anaconda2\lib\site-packages\keras\backend\theano_backend.py:1500: UserWarning: DEPRECATION: the 'st' parameter is not going to exist anymore as it is going to be replaced by the parameter 'stride'.
  mode='max')
C:\Program Files\Anaconda2\lib\site-packages\keras\backend\theano_backend.py:1500: UserWarning: DEPRECATION: the 'padding' parameter is not going to exist anymore as it is going to be replaced by the parameter 'pad'.
  mode='max')

对这个问题进行了检索,回答如下,但没有进行实践:

strongly suggest that you update cudnn to v7 (or at least v6). They fixed some of those type of errors.

Updating Theano to 0.10.beta1 could also fix that, as we have some work around in some cases for that.

The ideal would be to update both.

If you update Theano to 0.10.beta2 or the dev version, you will need to update libgpuarray version to 0.7.1

除此之外,当numpy大于1.16时,会有提示错误提示:

AttributeError: module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'

基于此有两种解决方式:

  1. upgrading theano的版本≥1.0.4
  2. downgrading numpy to 1.15.*

参考网址

http://www.zhongruitech.com/249400924.html
https://github.com/Theano/Theano/issues/6065
https://groups.google.com/forum/#!topic/theano-users/j8-6eLwxQUk
https://blog.csdn.net/hczhcz0905/article/details/80424023
https://blog.csdn.net/Xujian0000abcd/article/details/51352707

你可能感兴趣的:(深度学习实践)