Cómo cambiar el Backend con Keras (de TensorFlow a Theano)
Intenté cambiar el Backend con Keras (de TensorFlow a Theano) pero no lo logré. Seguí las temperaturas descritas aquí pero no funciona. Creé un keras.json en el directorio de keras (ya que no existía) pero no cambia nada cuando lo importo desde Python.
8 answers
Cree una carpeta .keras
(tenga en cuenta la .
al frente) en su directorio personal y coloque el archivo keras.json
allí.
Por ejemplo, /home/DaniPaniz/.keras/keras.json
(o ~/.keras/keras.json
en resumen) si está en un sistema tipo UNIX (macOS X, Linux, *BSD). En Windows desea crear la carpeta %USERPROFILE%/.keras
y poner el archivo JSON allí.
Alternativamente, también puede establecer la variable de entorno KERAS_BACKEND
:
KERAS_BACKEND=theano python mymodel.py
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-11 15:43:38
En caso de que desee cambiar la configuración de forma permanente, el json está disponible aquí: ~/.keras/keras.json
y puede cambiar el motor.
Para hacer esto dinámicamente en python 2.7 puede ejecutar:
from keras import backend as K
import os
def set_keras_backend(backend):
if K.backend() != backend:
os.environ['KERAS_BACKEND'] = backend
reload(K)
assert K.backend() == backend
set_keras_backend("theano")
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-18 21:40:34
En Windows, necesita encontrar .carpeta keras en su unidad C. Lo más probable es que esté en algún lugar de C:/users/username / . Ahí lo encontrarás .carpeta keras, contiene un archivo json, keras.json, ábrelo. Usted verá:
{
“backend”: “tensorflow”,
“floatx”: “float32”,
“epsilon”: 1e-07
}
Más o menos. reemplace 'tensorflow' por 'theano'. y guarde el archivo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-25 19:23:50
Tuve un problema en el que no podía from keras import backend
en absoluto hasta que configuré el backend a theano. Las respuestas proporcionadas deberían funcionar si puede importar backend, pero si no, solo use:
import os
os.environ['KERAS_BACKEND'] = 'theano'
import keras as ks
# Using Theano backend.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-18 21:40:02
Si está utilizando Windows, puede ejecutar desde la línea de comandos:
set "KERAS_BACKEND=theano"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-04 10:26:21
Escriba lo siguiente en el símbolo del sistema y presione entrar:
%USERPROFILE%/.keras/keras.json
Cambie el motor en el archivo de texto abierto y guárdelo. Estás acabado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-07 14:16:40
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")
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-18 21:40:46
Para sistemas Linux, lo oculto .el directorio keras se creará en el directorio personal del usuario. Para observar si se ha creado o no, ejecute el siguiente comando desde su directorio personal (el-a le permite ver archivos y directorios ocultos).
ls –a
Si el directorio está allí, entonces haga un cd en él y modifique los keras.archivo json. Si no está allí, entonces cree el directorio con
mkdir .keras
Luego crea el archivo con
touch keras.json
Luego edite el archivo para hacer la configuración cambios a los que hizo referencia para cambiar el motor backend a Theano.
Este proceso está cubierto completamente en este video.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-26 18:18:39