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".
  • 相关阅读:
    KVM_虚拟化技术
    Java面试题全集
    Web负载均衡与分布式架构
    Tomcat的目录结构和配置文件详解
    Apache HTTP Server 与 Tomcat 的三种连接方式介绍
    Java文件上传
    基础知识《十一》Java异常处理总结
    《转载》renameTo文件在windows环境下可以,在linux中报错
    《转载》Linux服务之搭建FTP服务器&&分布式文件服务器的比较
    oracle闪回数据
  • 原文地址:https://www.cnblogs.com/XUEYEYU/p/10913200.html
Copyright © 2011-2022 走看看