zoukankan      html  css  js  c++  java
  • keras 切换后端 TensorFlow,cntk,theano

    参考

    https://keras.io/#configuring-your-keras-backend

    https://keras.io/backend/


    Switching from one backend to another

    If you have run Keras at least once, you will find the Keras configuration file at:

    $HOME/.keras/keras.json

    If it isn't there, you can create it.


    linux

    ~/.keras/目录下 keras.json文件 如果不存在可以手动创建

    windows

    在系统盘中用户(users)当前用户名下的.keras文件夹中,有个keras.json文件。


    打开后更改"backend": "xxxxxx"

    xxxxx表示需要更换的后端,如"theano", "tensorflow", or "cntk",



    NOTE for Windows Users: Please replace $HOME with %USERPROFILE%.

    The default configuration file looks like this:

    {
        "image_data_format": "channels_last",
        "epsilon": 1e-07,
        "floatx": "float32",
        "backend": "tensorflow"
    }

    Simply change the field backend to "theano", "tensorflow", or "cntk", and Keras will use the new configuration next time you run any Keras code.

    You can also define the environment variable KERAS_BACKEND and this will override what is defined in your config file :

    KERAS_BACKEND=tensorflow python -c "from keras import backend"
    Using TensorFlow backend.
    

    In Keras it is possible to load more backends than "tensorflow", "theano", and "cntk". Keras can use external backends as well, and this can be performed by changing the keras.json configuration file, and the "backend" setting. Suppose you have a Python module called my_module that you wanted to use as your external backend. The keras.json configuration file would be changed as follows:

    {
        "image_data_format": "channels_last",
        "epsilon": 1e-07,
        "floatx": "float32",
        "backend": "my_package.my_module"
    }
    

    An external backend must be validated in order to be used, a valid backend must have the following functions: placeholder, variable and function.

    If an external backend is not valid due to missing a required entry, an error will be logged notifying which entry/entries are missing.


    keras.json details

    The keras.json configuration file contains the following settings:

    {
        "image_data_format": "channels_last",
        "epsilon": 1e-07,
        "floatx": "float32",
        "backend": "tensorflow"
    }
    

    You can change these settings by editing $HOME/.keras/keras.json.

    • image_data_format: String, either "channels_last" or "channels_first". It specifies which data format convention Keras will follow. (keras.backend.image_data_format() returns it.)
    • For 2D data (e.g. image), "channels_last" assumes (rows, cols, channels) while "channels_first" assumes (channels, rows, cols).
    • For 3D data, "channels_last" assumes (conv_dim1, conv_dim2, conv_dim3, channels) while "channels_first" assumes (channels, conv_dim1, conv_dim2, conv_dim3).
    • epsilon: Float, a numeric fuzzing constant used to avoid dividing by zero in some operations.
    • floatx: String, "float16", "float32", or "float64". Default float precision.
    • backend: String, "tensorflow", "theano", or "cntk".
  • 相关阅读:
    【bzoj3083】遥远的国度 树链剖分+线段树
    【bzoj2226】[Spoj 5971] LCMSum 欧拉函数
    xml、json的序列化与反序列化
    什么是安全证书,访问者到底是怎么校验安全证书的,服务端返回安全证书后,客户端再向谁验证呢?
    查看发票组代码后的总结和有感
    网址的正则表达式、常用正则表达式、在线正则表达式检测
    XamlParseException异常
    委托,lambda,匿名方法
    windows中断与共享的连接(samba)
    linux ubuntu 11.04 samba 服务器设置
  • 原文地址:https://www.cnblogs.com/XUEYEYU/p/10913200.html
Copyright © 2011-2022 走看看