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

1,安装pip

sudo apt-get install python3-setuptools
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位系统上没有对应的版本!用源文件安装又很复杂)

vim ~/.keras/keras.json
{
 
  "image_dim_ordering":"tf",
 
  "epsilon":1e-07,
 
  "floatx":"float32",
 
  "backend":"theano"
}

 5,测试theano

import numpy as np 
import time 
import theano 
A = np.random.rand(1000,10000).astype(theano.config.floatX) 
B = np.random.rand(10000,1000).astype(theano.config.floatX) 
np_start = time.time() 
AB = A.dot(B) 
np_end = time.time() 
X,Y = theano.tensor.matrices('XY') 
mf = theano.function([X,Y],X.dot(Y)) 
t_start = time.time() 
tAB = mf(A,B) 
t_end = time.time() 
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %( 
                      np_end-np_start, t_end-t_start)) 
print("Result difference: %f" % (np.abs(AB-tAB).max(), ))

总结

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

标签:
ubuntu,安装,theano,keras,theano和keras

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“ubuntu系统theano和keras的安装方法”

暂无“ubuntu系统theano和keras的安装方法”评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?