在{'theano','tensorflow'}断言_backend断言

时间:2017-04-12 18:38:44

标签: python tensorflow theano keras

我正在尝试运行this code,但收到以下错误:

Traceback (most recent call last):
  File "classifier_from_little_data_script_3.py", line 39, in <module>
    from keras import applications
  File "C:\Python35\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import activations
  File "C:\Python35\lib\site-packages\keras\activations.py", line 3, in <module>
    from . import backend as K
  File "C:\Python35\lib\site-packages\keras\backend\__init__.py", line 36, in <module>
    assert _backend in {'theano', 'tensorflow'}
AssertionError

我尝试寻找此错误的原因,但无法找到解决方案。我该如何解决这个问题?

编辑1

这是keras.json文件:

{
    "image_dim_ordering": "tf",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tf"
}

编辑2

我已将后端更改为tensorflow,但收到以下错误:

ValueError: The shape of the input to "Flatten" is not fully defined (got (None, None, 512). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.

我为第二次修改here添加了一个单独的问题。

感谢。

1 个答案:

答案 0 :(得分:1)

你的keras.json应该是这样的

{
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow" 
}

注意差异"backend" : "tensorflow"与您拥有的"backend" : "tf"

之间的区别