温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ubuntu如何安装theano和keras

发布时间:2022-10-24 11:00:40 来源:亿速云 阅读:110 作者:iii 栏目:服务器

这篇文章主要介绍“ubuntu如何安装theano和keras”,在日常操作中,相信很多人在ubuntu如何安装theano和keras问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”ubuntu如何安装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”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI