C:\Users\Administrator>python Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> import keras Using TensorFlow backend. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Anaconda2\lib\site-packages\keras\__init__.py", line 2, in <module> from . import backend File "C:\Anaconda2\lib\site-packages\keras\backend\__init__.py", line 68, in <module> from .tensorflow_backend import * File "C:\Anaconda2\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in <module> import tensorflow as tf ImportError: No module named tensorflow >>> import keras Using Theano backend. WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
方法一:将C:\Anaconda2\Lib\site-packages\keras\backend\__init__.py的line 27修改
# Default backend: TensorFlow. #_BACKEND = 'tensorflow' _BACKEND = 'theano' 然后,python-> import keras
方法二: 出现 tensorflow提示错误的话,需要修改下面的位置的内容
[html] view plain copy print ? C:\Users\Administrator\.keras\keras.json { "image_dim_ordering":"tf", "epsilon":1e-07, "floatx":"float32", "backend":"tensorflow" } C:\Users\Administrator\.keras\keras.json { "image_dim_ordering":"tf", "epsilon":1e-07, "floatx":"float32", "backend":"tensorflow" }将 [html] view plain copy print ? { "image_dim_ordering": "tf", "epsilon": 1e-07, "floatx": "float32", "backend": "theano" } { "image_dim_ordering": "tf", "epsilon": 1e-07, "floatx": "float32", "backend": "theano" }