keras的backend 设置 tensorflow,theano

window 系统环境安装步骤:

1.首先是安装Python,建议安装anaconda
2.安装完anaconda后打开anaconda promp命令行promp,输入conda list.
可以看到已经安装的库以及版本等信息,注意此时没有keras.
3.通过 conda install keras 或  pip install keras 直接安装。(会默认的给你安装keras最新版本和所需要的theano)
4.安装完成之后,就可以打开notebook,输入import keras 检查是否成功。
5.因为windows版本的tensorflow刚刚才推出,所以目前支持性不太好。
但是keras的backend 同时支持tensorflow和theano.
并且默认是tensorflow,因此在win本上需要更改backend为theano才能运行。
这是官网的配置文档:http://keras-cn.readthedocs.io/en/latest/backend/点击打开链接

如果已经运行过一次Keras,你将在下面的目录下找到Keras的配置文件:~/.keras/keras.json
如果该目录下没有该文件,你可以手动创建一个
将文件的默认配置如下:

C:\Users\Administrator>python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda2\lib\site-packages\keras\__init__.py", line 2, in <module>
    from . import backend
  File "C:\Anaconda2\lib\site-packages\keras\backend\__init__.py", line 68, in <module>
    from .tensorflow_backend import *
  File "C:\Anaconda2\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in <module>
    import tensorflow as tf
ImportError: No module named tensorflow
>>> import keras
Using Theano backend.
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.


C:\Users\Administrator>python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda2\lib\site-packages\keras\__init__.py", line 2, in <module>
    from . import backend
  File "C:\Anaconda2\lib\site-packages\keras\backend\__init__.py", line 68, in <module>
    from .tensorflow_backend import *
  File "C:\Anaconda2\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in <module>
    import tensorflow as tf
ImportError: No module named tensorflow
>>> import keras
Using Theano backend.
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.

方法一:将C:\Anaconda2\Lib\site-packages\keras\backend\__init__.py的line 27修改


# Default backend: TensorFlow.
#_BACKEND = 'tensorflow'
_BACKEND = 'theano'
然后,python-> import keras


方法二: 出现 tensorflow提示错误的话,需要修改下面的位置的内容

  1. C:\Users\Administrator\.keras\keras.json  
  2. {  
  3. "image_dim_ordering":"tf",  
  4. "epsilon":1e-07,  
  5. "floatx":"float32",  
  6. "backend":"tensorflow"  
  7. }  
C:\Users\Administrator\.keras\keras.json
{
"image_dim_ordering":"tf",
"epsilon":1e-07,
"floatx":"float32",
"backend":"tensorflow"
}

  1. {  
  2.     "image_dim_ordering": "tf",   
  3.     "epsilon": 1e-07,   
  4.     "floatx": "float32",   
  5.     "backend": "theano"  
  6. }  
{
    "image_dim_ordering": "tf", 
    "epsilon": 1e-07, 
    "floatx": "float32", 
    "backend": "theano"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值