Keras 切换后端方式(Theano和TensorFlow)
作者:PlusTang124 时间:2023-05-30 22:35:03
实验室新装了keras,发现keras默认后端是tensorflow,想换回theano,看了官方文档也没搞懂,最终搞定,很简单。
中文文档的描述:keras中文文档,切换后端
其实就是在C:\Users\75538(75538是我的windos用户名字,找你对应的用户名就行)下有个文件夹.keras,里面有keras.json文件,改一下里面的内容就好了,如果没有文件夹和文件,手动创建就行。
用theano的话,keras.json写入
{
"image_dim_ordering": "th",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "theano"
}
用thesorflow的话,keras.json写入
{
"image_dim_ordering": "tf",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
最后保存就可以了
补充知识:anaconda2-keras安装;keras后端修改
一、anaconda2-keras安装
在anaconda2平台下,安装keras库。记录一下,主要是我一开始觉得很简单,pip一下就行了,结果我用pip install keras安装时,就遇到了这样一个问题:ImportError: cannot import name np_utils。
解决方案:
That tutorial was written on June 9th, 2016.Keras 2 was released in March 2017. Try installing the old version, using pip installkeras==1.2.2.
总结一下就是:
1.先装上anaconda2_python2.7
2.再在anancona prompt中用 pip install keras==1.2.2 装Keras
3.spyder中输入 import Keras,检查是否安装成功
二、keras后端修改
代码用的后端是'theano',故要修改后端
将C:\Anaconda2\Lib\site-packages\keras\backend\__init__.py的line 27修改
# Default backend: TensorFlow.
#_BACKEND = 'tensorflow'
_BACKEND = 'theano'
然后,python-> import keras,检查是否修改成功。
来源:https://blog.csdn.net/tangwenbo124/article/details/52627774
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决Jupyter因卸载重装导致的问题修复
Python编程判断这天是这一年第几天的方法示例
![](https://img.aspxhome.com/file/2023/8/89378_0s.jpg)
python机器学习混淆矩阵及confusion matrix函数使用
![](https://img.aspxhome.com/file/2023/6/92436_0s.png)
mysql查询字符串替换语句小结(数据库字符串替换)
使用MHTML 解决 data URI scheme 的浏览器兼容问题
PHP实现表单处理方法详解
为什么不压缩 HTML
Python用于学习重要算法的模块pygorithm实例浅析
pytorch_detach 切断网络反传方式
python使用pymysql实现操作mysql
简介JavaScript错误处理机制
推荐系统MostPopular算法的Python实现方式
Python脚本实现网卡流量监控
Oracle基本PLSQL的使用实例详解
使用Python监控文件内容变化代码实例
将Reporting services的RDL文件拷贝到另外一台机器时报Data at the root level is invalid的解决方法
Go简单实现协程池的实现示例
![](https://img.aspxhome.com/file/2023/2/105142_0s.jpg)
PyCharm2020.1.2社区版安装,配置及使用教程详解(Windows)
![](https://img.aspxhome.com/file/2023/1/134671_0s.png)
MySQL Order By索引优化方法
CentOS 7下部署php7.1和开启MySQL扩展的方法教程
![](https://img.aspxhome.com/file/2023/3/82853_0s.png)