tensorflow: 'module' object has no attribute

当前的tensorflow版本是
tf.__version__
Out[4]: '2.0.0-dev20190526'

运行之前可以运行的tensorflow代码,出现的问题

'module' object has no attribute

In [1]: import tensorflow as tf

In [2]: tf.reset_default_graph()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-c193d79f7d5a> in <module>()
----> 1 tf.reset_default_graph()

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

In [3]: Y = tf.placeholder(tf.float32, [None, 6])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-7051f9cffff8> in <module>()
----> 1 Y = tf.placeholder(tf.float32, [None, 6])

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

可以看下官方文档

https://www.tensorflow.org/beta/guide/migration_guide

Convert Your Existing Code to TensorFlow 2.0

这里先使用最简单的方法解决上面的问题

It is still possible to run 1.X code, unmodified (except for contrib), in TensorFlow 2.0:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

 

'module' object has no attribute 'contrib' 

tf.contrib.rnn.MultiRNNCell(lstm_layers)

  应该怎样调用到MultiRNNCell

cd到目录/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops

 grep -nr BasicLSTMCell ./

/rnn_cell_impl.py:634:@tf_export(v1=["nn.rnn_cell.BasicLSTMCell"])

tf.nn.rnn_cell.BasicLSTMCell(N_HIDDEN_UNITS, forget_bias=1.0)
Out[130]: <tensorflow.python.ops.rnn_cell_impl.BasicLSTMCell at 0x7f5cf19a4f10>

正确的方法还是看代码怎样升级到2.0 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值