How to switch Backend with Keras (from TensorFlow to Theano)

前端 未结 8 1377
南旧
南旧 2020-12-07 16:23

I tried to switch Backend with Keras (from TensorFlow to Theano) but did not manage. I followed the temps described here but it doesn\'t work. I created a keras.json in the

相关标签:
8条回答
  • 2020-12-07 16:55

    Type following on command prompt and press enter:

    %USERPROFILE%/.keras/keras.json
    

    Change backend in the opened text file and save it. You are done.

    0 讨论(0)
  • 2020-12-07 16:56

    I had an issue where I could not from keras import backend at all until I set the backend to theano. The provided answers should work if you can import backend, but if not, just use:

    import os
    os.environ['KERAS_BACKEND'] = 'theano'
    import keras as ks
    # Using Theano backend.
    
    0 讨论(0)
  • 2020-12-07 17:08

    Create a .keras (note the . in front) folder in you home directory and put the keras.json file there.

    For example, /home/DaniPaniz/.keras/keras.json (or ~/.keras/keras.json in short) if you are on a UNIX like system (MacOS X, Linux, *BSD). On Windows you want to create the folder %USERPROFILE%/.keras and put the JSON file there.

    Alternatively, you can also set the environment variable KERAS_BACKEND:

    KERAS_BACKEND=theano python mymodel.py
    
    0 讨论(0)
  • 2020-12-07 17:08

    If you're using windows you can run from command line:

    set "KERAS_BACKEND=theano"

    0 讨论(0)
  • 2020-12-07 17:10
    from keras import backend as K
    from os import environ
    
    # user defined function to change keras backend
    def set_keras_backend(backend):
        if K.backend() != backend:
           environ['KERAS_BACKEND'] = backend
           reload(K)
           assert K.backend() == backend
    
    # call the function with "theano"
    set_keras_backend("theano")
    
    0 讨论(0)
  • 2020-12-07 17:11

    For Linux systems, the hidden .keras directory will be created in the user’s home directory. To observe whether or not it has been created, run the following command from your home directory (the -a allows you to see hidden files and directories).

    ls –a 
    

    If the directory is there, then cd into it and modify the keras.json file. If it’s not there, then create the directory with

    mkdir .keras
    

    Then create the file with

    touch keras.json 
    

    Then edit the file to make the config changes you referenced to change the backend engine to Theano.

    This process is covered fully in this video.

    0 讨论(0)
提交回复
热议问题