'Tensorflow'模块没有属性 [英] module 'Tensorflow' has no atributte

查看:161
本文介绍了'Tensorflow'模块没有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用TensorFlow时,我在Google Colab中遇到这些奇怪的错误,

I'm getting these weird errors in Google Colab when using TensorFlow, like:

AttributeError:模块"tensorflow"没有属性'reset_default_graph'

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

模块'tensorflow'没有属性'占位符'

module 'tensorflow' has no attribute 'placeholder'

我们将不胜感激.

推荐答案

之所以会出现此问题,是因为GoogleColab上安装的当前版本是 tensorflow 2.2.0 .显然,您使用的代码假定已安装 tensorflow 1.x .

This problem happens because the current version installed on GoogleColab is tensorflow 2.2.0. And apparently, the code you're using assumes that tensorflow 1.x is installed.

因此,您可以使用两种方法解决此问题:

So, you can fix this issue using two ways:

  • 将您的 tensorflow 降级为 1.x ,就像这样:

 !pip install tensorflow==1.15

  • 或者您可以使用 tensorflow.comat.v1 包中提供的方法,例如 tf.compat.v1.reset_default_graph ,而不是 tf.reset_default_graph tf.compat.v1.placeholder ,而不是 tf.placeholder .

  • Or you can use the methods provided in tensorflow.comat.v1 package like tf.compat.v1.reset_default_graph instead of tf.reset_default_graph and tf.compat.v1.placeholder instead of tf.placeholder.

    我真的鼓励第一个解决方案,因为第二个解决方案将需要进行很多更改,否则可能会导致错误.

    I really encourage the first solution as the second solution will require a lot of changes that can lead to mistakes.

    我真的用过

    这篇关于'Tensorflow'模块没有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆