【问题标题】:assert _backend in {'theano', 'tensorflow'} AssertionError在 {'theano', 'tensorflow'} AssertionError 中断言 _backend
【发布时间】:2017-04-12 18:38:43
【问题描述】:

我正在尝试运行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

谢谢。

【问题讨论】:

  • 你能打印出你的keras.json文件吗?
  • @MarcinMożejko 感谢您的友好回复。当然,请参阅问题中的EDIT 1
  • 所以你应该把tf改为tensorflow
  • @MarcinMożejko 请参阅我的问题中的 EDIT 2,了解将后端更改为“tensorflow”时出现的错误。谢谢。

标签: python tensorflow theano keras


【解决方案1】:

你的 keras.json 应该是这样的

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

注意"backend" : "tensorflow" 与您所拥有的"backend" : "tf" 的区别

【讨论】:

  • 感谢您的友好回复。当我将后端更改为“tensorflow”时,请参阅我的问题中的 EDIT 2。谢谢。
  • 我看到了编辑,但我建议接受这个答案并打开另一个包含新错误详细信息的问题。
  • 是的,当然。我已经接受了答案,并在此处添加了一个新问题:stackoverflow.com/questions/43383114/…。感谢您的支持
猜你喜欢
  • 2021-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-28
  • 2016-12-25
  • 2016-09-02
  • 1970-01-01
相关资源
最近更新 更多