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"
}
根据引用,你提到你参照了"coco.yaml"的文件格式来调整"VisDron.yaml"的格式。根据这个描述,我理解你是在修改文件的存储格式。 另外,根据引用,你提到在使用Keras时遇到了一个KeyError &#39;acc&#39;的错误。这个错误是由于不同版本的Keras使用了不同的命名约定,而你的代码中使用了&#39;acc&#39;作为指标名称。相应地,你需要将代码中的&#39;acc&#39;更换为&#39;accuracy&#39;或者根据具体版本进行适配。同样的情况也适用于&#39;val_acc&#39;指标。 至于你提到的问题,"val: Error loading data from C:\Users\Administrator\Desktop\GGS\VOCdevkit\labels\train: val: No images found",这个错误是由于在指定路径下没有找到对应的图像文件导致的。请确保路径中的文件夹和文件名正确,并且该文件夹中包含了需要的图像文件。 总之,你需要检查路径是否正确,并确保所需的图像文件位于指定的文件夹中。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [Error:loading data from ……](https://blog.csdn.net/xzg104/article/details/129281008)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [解决Keyerror acc KeyError: val_acc问题](https://download.csdn.net/download/weixin_38612304/13710164)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值