AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘解决办法
·
在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)
最后运行不报错。
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)