断言错误:_backend必须是{'theano', 'tensorflow'}中的一个。

3

我正在尝试运行这段代码,但是遇到了以下错误:

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.

我已经为第二次编辑添加了一个单独的问题,在这里

谢谢。


1
你能打印出你的 keras.json 文件吗? - Marcin Możejko
@MarcinMożejko 感谢您的友好回复。当然,请查看问题中的 EDIT 1 - Simplicity
2
所以你应该将 tf 改为 tensorflow - Marcin Możejko
@MarcinMożejko 请查看我在问题中的 EDIT 2,了解我在将后端更改为“tensorflow”时遇到的错误。谢谢。 - Simplicity
1个回答

1
你的 keras.json 应该长这样。
{
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow" 
}

请注意以下代码中的差异:"backend" : "tensorflow""backend" : "tf"

感谢您的回复。请查看我在问题中的 EDIT 2,当我将后端更改为“tensorflow”时。谢谢。 - Simplicity
我看到了你的编辑,但我建议接受这个答案并开一个新问题来详细描述新错误。 - parsethis
是的,当然。我已经接受了答案,并添加了一个新的问题,链接在这里:http://stackoverflow.com/questions/43383114/valueerror-the-shape-of-the-input-to-flatten-is-not-fully-defined。感谢您的支持。 - Simplicity

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接