系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > Linux教程 > 详细页面

ubuntu系统theano和keras的安装方法

时间:2019-12-30来源:系统城作者:电脑系统城

说明:系统是unbuntu14.04LTS,32位的操作系统,以前安装了python3.4,现在想要安装theano和keras。步骤如下:

1,安装pip


 
  1. sudo apt-get install python3-setuptools
  2. sudo easy_install3 pip

2,安装g++

 sudo apt-get install g++

采用上述命令安装g++,安装完成后可用g++ -version查看是否安装完成。注意,如果没有安装g++,在import theano时会出现以下错误:

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.
搜了一下是因为theano采用g++编译的话速度比较快,在网上找到的大部分解决方案都是基于Anaconda安装的,解决方法是:

conda install mingw libpython

3,安装theano

sudo pip3 install theano

 该命令会自动下载theano所需要的依赖,包括numpy,scipy等等。

4,安装keras

sudo pip3 install keras

 最后需要注意的是,keras默认的backend是tensorflow,我们需要的是theano,所以需要修改下设置。(而且tensorflow用pip3安装,在32位系统上没有对应的版本!用源文件安装又很复杂)


 
  1. vim ~/.keras/keras.json
  2. {
  3.  
  4. "image_dim_ordering":"tf",
  5.  
  6. "epsilon":1e-07,
  7.  
  8. "floatx":"float32",
  9.  
  10. "backend":"theano"
  11. }

 5,测试theano


 
  1. import numpy as np
  2. import time
  3. import theano
  4. A = np.random.rand(1000,10000).astype(theano.config.floatX)
  5. B = np.random.rand(10000,1000).astype(theano.config.floatX)
  6. np_start = time.time()
  7. AB = A.dot(B)
  8. np_end = time.time()
  9. X,Y = theano.tensor.matrices('XY')
  10. mf = theano.function([X,Y],X.dot(Y))
  11. t_start = time.time()
  12. tAB = mf(A,B)
  13. t_end = time.time()
  14. print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
  15. np_end-np_start, t_end-t_start))
  16. print("Result difference: %f" % (np.abs(AB-tAB).max(), ))

总结

以上所述是小编给大家介绍的ubuntu系统theano和keras的安装方法,希望对大家有所帮助!

分享到:

相关信息

  • linux定时关机设置教程

    当linux在运作时不能直接关闭电源容易将档案系统损毁,因此需要用shutdown以安全的方式关闭,那么这个操作该怎么实现呢?下面就为大家带来了详细教程。...

    2022-11-07

  • linux强制删除文件教程

    由于linux系统和我们常用的windows系统是不一样的,所以如果是初学者,可能会不知道linux怎么强制删除文件,其实我们只要打开终端,使用命令就可以删除了。...

    2022-11-03

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载