module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘问题的完美解决
生活随笔
收集整理的這篇文章主要介紹了
module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘问题的完美解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題描述:
Instructions for updating: Use keras.layers.Dense instead. Traceback (most recent call last):File "run_cnn.py", line 200, in <module>model = TextCNN(config)File "D:\MY DATA\學習資料\研究生\深度學習\text-classification-cnn-rnn-master\cnn_model.py", line 43, in __init__self.cnn()File "D:\MY DATA\學習資料\研究生\深度學習\text-classification-cnn-rnn-master\cnn_model.py", line 61, in cnnfc = tf.contrib.layers.dropout(fc, self.keep_prob) AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'原因:
TensorFlow 2 刪除了部分v1的庫
很多代碼大佬們都是用v1版本寫的,所以一種解決辦法是將tensorflow版本降回v1,我這么干了,結果引發更大的問題,因為菜啊。。。找了好久,下面這種方法完美解決。
解決辦法:
將
cell = tf.contrib.rnn.BasicLSTMCel
用
cell = tf.compat.v1.nn.rnn_cell.BasicLSTMCell
代替就可以完美的解決出現的問題。得到的結果沒啥區別。
總結
以上是生活随笔為你收集整理的module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘问题的完美解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 养成女友?我训练出了一个“杨超越”聊天机
- 下一篇: No module named ‘__m