对于 Windows 用户,在我的 Windows 10 中,Anaconda 创建 .bat 文件的方式似乎有点奇怪,或者至少它们是如何执行的。它们在 cmd 中显示写入的每个命令。
至少在我的情况下是这样。
所以对我来说它总是说:"KERAS_BACKEND=theano",但那没有被执行。
检查一下:
在此路径中:<your_conda_install_location>\envs\<your_environment_name>\etc\conda\activate.d
你会找到一个.bat 文件。
(将路径引用中的 <whatever> 替换为您的系统特定名称)
还要检查keras.json 文件是否将后端设置为 tensorflow。
我的内容是:
:: Figure out the default Keras backend by reading the config file.
python %CONDA_PREFIX%\etc\keras\load_config.py > temp.txt
set /p KERAS_BACKEND=<temp.txt
del temp.txt
:: Try to use the default Keras backend.
:: Fallback to Theano if it fails (Theano always works).
python -c "import keras" 1> nul 2>&1
if errorlevel 1 (
ver > nul
set "KERAS_BACKEND=theano"
python -c "import keras" 1> nul 2>&1
)
我只是添加了@echo off,因此它不会显示所有代码,并添加了一些控制台输出来告诉我实际执行了什么。这同时作为一种调试器或证明它实际上没有执行set "KERAS_BACKEND=theano"
(向下滚动查看完整编辑的 .bat 文件)
在上面我补充说:
@echo off
:: message variables
set er0=used default Keras backend tensorflow
set er1=used fallback Keras backend theano
对于消息:
结尾处:: Figure out the default Keras backend by reading the config file.:
if errorlevel 0 (
echo %er0%
)
在:: Fallback to Theano if it fails (Theano always works)的if里面:
echo %er1%
现在是.bat 的完整代码,以获得更好的概览:
@echo off
:: message variables
set er0=used default Keras backend tensorflow
set er1=used fallback Keras backend theano
:: Figure out the default Keras backend by reading the config file.
python %CONDA_PREFIX%\etc\keras\load_config.py > temp.txt
set /p KERAS_BACKEND=<temp.txt
del temp.txt
if errorlevel 0 (
echo %er0%
)
:: Try to use the default Keras backend.
:: Fallback to Theano if it fails (Theano always works).
python -c "import keras" 1> nul 2>&1
if errorlevel 1 (
ver > nul
set "KERAS_BACKEND=theano"
echo %er1%
python -c "import keras" 1> nul 2>&1
)
因此,现在 cmd 上只有消息说明是否使用了默认后端,或者如果出现错误,它是否使用了 theano 后端。
另外一定要检查keras.json 的后端设置为 tensorflow。
我希望这可以帮助一些 Windows 用户。