AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘解决办法
AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘以及AttributeError: module 'tensorflow.compat.v1' has no attribute ‘contrib‘
文章共234字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
在TensorFlow2环境下执行1.X版本的代码时报错:
AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘
当然第一时间想到的是利用 如下代码 来解决问题(大部分情况都是这样),
tf.compat.v1
但是又出现以下报错
AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘contrib‘
表示这个库中也没有该函数。
查阅资料以及实验发现,是选择库的问题,需要修改如下:
# 原始代码
lstm_enc = tf.contrib.rnn.LSTMCell(num_units)
# 修改后代码
lstm_enc = tf.compat.v1.nn.rnn_cell.LSTMCell(num_units)
最后运行不报错。
更多推荐
已为社区贡献5条内容
所有评论(0)