首页 文章

Keras tensorflow给出错误“no attribute 'control_flow_ops'”

提问于
浏览
11

我试图第一次运行keras . 我安装了以下模块:

pip install keras --user
pip install tensorflow --user

然后尝试运行https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py .

但它给了我:

AttributeError: 'module' object has no attribute 'control_flow_ops'

这些是我正在使用的版本 .

print tensorflow.__version__
0.11.0rc0
print keras.__version__
1.1.0

如何让keras与tensorflow一起运行?

2 回答

  • 22

    Keras和TF之间存在问题,可能tf.python.control_flow_ops不存在或不再可见 . 使用下面的import语句可以解决此问题

    import tensorflow as tf
    tf.python.control_flow_ops = tf
    

    详情请查看:https://github.com/fchollet/keras/issues/3857

  • 1

    当事实证明 keras 正在使用 Theano 后端时,我遇到了这个问题 . 要修复它,请执行以下操作之一:

    • ~/.keras/keras.json 设置 "backend": "tensorflow" .

    • 将环境变量 KERAS_BACKEND 设置为 tensorflow .

    有关更多信息,请参见Keras backend文档 .

相关问题