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".
  • 相关阅读:
    [JNA系列]Java调用Delphi编写的Dll之Delphi与JAVA基本数据类型对比
    JSON和数据集互相转换单元
    Windows管理多个java版本--解决'has value '1.8',but'1.7' is required'的方法
    Spring+SpringMVC+MyBatis+Maven框架整合
    让你的程序通过XP防火墙
    内存共享【Delphi版】
    自学k8s-安装docker特定版本技巧
    自学k8s-k8s集群环境搭建
    自学k8s-安装过程为下载flannel.yml和镜像文件,而需要设置的代理
    Centos开放指定端口命令
  • 原文地址:https://www.cnblogs.com/XUEYEYU/p/10913200.html
Copyright © 2011-2022 走看看