【问题标题】:Keras + TensorFlow: “module 'tensorflow' has no attribute 'merge_all_summaries''”Keras + TensorFlow:“模块‘tensorflow’没有属性‘merge_all_summaries’’”
【发布时间】:2017-03-03 18:03:07
【问题描述】:

Keras + tensorflow gives the error "no attribute 'control_flow_ops'" 非常相似,来自https://blog.keras.io/building-autoencoders-in-keras.html 的卷积自动编码器示例我得到了错误

[...]lib/python3.5/site-packages/keras/callbacks.py in _set_model(self, model)
    478                     tf.histogram_summary('{}_out'.format(layer),
    479                                          layer.output)
--> 480         self.merged = tf.merge_all_summaries()
    481         if self.write_graph:
    482             if parse_version(tf.__version__) >= parse_version('0.8.0'):

AttributeError: module 'tensorflow' has no attribute 'merge_all_summaries'

我试过了

import tensorflow as tf
tf.merge_all_summaries = tf

但这没有用。我该怎么办?

AttributeError: 'module' object has no attribute 'merge_all_summaries' 中提到了错误。我也有版本 1.0.0。但是解决方案是什么?我不想降级 TensorFlow。

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    Make42 是绝对正确的,他们在their answer 中描述的更改必须进行才能迁移代码库以使用 TensorFlow 1.0。但是,您看到的错误出现在 Keras 库本身中。幸运的是,这些错误已在 Keras 代码库 since January 2017 中修复,因此升级到 Keras 1.2.2 或更高版本将为您修复错误。

    【讨论】:

    • 我们可以用 anaconda 或至少 pip 来做到这一点吗?
    • 我认为pip install -U keras 应该这样做。
    【解决方案2】:

    答案是酌情迁移。查看https://www.tensorflow.org/install/migration。看到这里

    - tf.merge_summary
        - should be renamed to tf.summary.merge
    - tf.train.SummaryWriter
        - should be renamed to tf.summary.FileWriter
    

    (其实SummaryWriter也改了。)所以用

    代替
    import tensorflow as tf
    tf.merge_all_summaries = tf
    

    你应该写

    import tensorflow as tf
    tf.merge_all_summaries = tf.summary.merge_all
    tf.train.SummaryWriter = tf.summary.FileWriter
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 2019-05-25
      • 1970-01-01
      • 2019-10-05
      • 2019-08-04
      • 1970-01-01
      • 2019-08-09
      相关资源
      最近更新 更多