目录

出现错误界面

1.问题原因

2.解决办法

(1)在调用之前首先添加如下代码块并执行

(2)查找响应函数对应的函数调用前缀。

注:若出现错误也是LSTM预测,可直接复制如下代码:

最后问题解决,代码最后成功运行


anaconda下:

tensorflow版本:tensorflow2.3.0

python版本:python3.7

出现错误界面

1.问题原因

原因是tensorflow 2.0版本之后把contrib这个库取消了

2.解决办法

简单说法:到tensorflow官网查询相对应的函数调用方式即可。

(1)在调用之前首先添加如下代码块并执行

# import tensorflow as tf
# tf.compat.v1.reset_default_graph()import tensorflow.compat.v1 as tf
tf.reset_default_graph()tf.compat.v1.disable_eager_execution()

(2)查找响应函数对应的函数调用前缀。

tensorflow官网TensorFlow (google.cn)

在搜索框直接输入对应函数即可。

以我的函数 DropoutWrapper为例:

直接输入红色框住部分的函数调用即可。

亲测 tf.compat.v1. 对绝大多数部分的函数都可以使用

涉及到tf调用函数的部分全部加上tf.compat.v1.  

最终问题解决,代码执行成功。

注:若出现错误也是LSTM预测,可直接复制如下代码:

def lstm_cell(size_layer):return tf.compat.v1.nn.rnn_cell.LSTMCell(size_layer, state_is_tuple = False)rnn_cells = tf.compat.v1.nn.rnn_cell.MultiRNNCell([lstm_cell(size_layer) for _ in range(num_layers)],state_is_tuple = False,)self.X = tf.compat.v1.placeholder(tf.compat.v1.float32, (None, None, size))self.Y = tf.compat.v1.placeholder(tf.compat.v1.float32, (None, output_size))drop = tf.compat.v1.nn.rnn_cell.DropoutWrapper(rnn_cells, output_keep_prob = forget_bias)self.hidden_layer = tf.compat.v1.placeholder(tf.compat.v1.float32, (None, num_layers * 2 * size_layer))self.outputs, self.last_state = tf.compat.v1.nn.dynamic_rnn(drop, self.X, initial_state = self.hidden_layer, dtype = tf.compat.v1.float32)self.logits = tf.compat.v1.layers.dense(self.outputs[-1], output_size)self.cost = tf.compat.v1.reduce_mean(tf.square(self.Y - self.logits))self.optimizer = tf.compat.v1.train.AdamOptimizer(learning_rate).minimize(self.cost)
def forecast():#此处为部分代码tf.compat.v1.reset_default_graph()modelnn = Model(learning_rate, num_layers, df_log.shape[1], size_layer, df_log.shape[1], dropout_rate)sess = tf.compat.v1.InteractiveSession()sess.run(tf.compat.v1.global_variables_initializer())date_ori = pd.to_datetime(df.iloc[:, 0]).tolist()

最后问题解决,代码最后成功运行

【最简单解决办法】:module ‘tensorflow.compat.v1‘ has no attribute ‘contrib‘相关推荐

  1. TensorFlow 2——【module ‘tensorflow.compat.v1‘ has no attribute ‘contrib‘】解决方案

    问题描述 Traceback (most recent call last):   File "D:/Code/Project/a18/ocr/demo.py", line 16, ...

  2. module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘问题的完美解决

    问题描述: Instructions for updating: Use keras.layers.Dense instead. Traceback (most recent call last):F ...

  3. AttributeError: module ‘tensorflow_core.compat.v1‘ has no attribute ‘contrib‘

    由于tensorflow版本问题,在tensorflow2.x版本里没有contrib组件,因此无法使用LSTMRNN实例中的sequence_loss_by_example函数. Attribute ...

  4. tensorflow.compat.v1 has no attribute contrib

  5. 成功解决AttributeError: module tensorflow.compat has no attribute v1

    成功解决AttributeError: module 'tensorflow.compat' has no attribute 'v1' 目录 解决问题 解决思路 解决方法 1.tf.Session ...

  6. 成功解决AttributeError: module 'tensorflow.nn.rnn_cell' has no attribute 'linear'

    成功解决AttributeError: module 'tensorflow.nn.rnn_cell' has no attribute 'linear' 目录 解决问题 解决思路 解决方法 解决问题 ...

  7. 成功解决AttributeError: module 'tensorflow.python.keras' has no attribute 'Model'

    成功解决AttributeError: module 'tensorflow.python.keras' has no attribute 'Model' 目录 解决问题 解决方法 解决问题 File ...

  8. TensorFlow 2——替换【tensorflow.compat.v1.contrib.rnn.LSTMCell】解决方案

    问题描述 Traceback (most recent call last):   File "D:/Code/Project/a18/ocr/demo.py", line 16, ...

  9. ImportError: No module named tensorflow.compat.v1 忽略已经安装的某个包版本 忽略已安装版本...

    ImportError: No module named tensorflow.compat.v1 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声 ...

最新文章

  1. 超详细中文预训练模型ERNIE使用指南
  2. 利用sendmail搭建邮件服务器
  3. bzoj 1028: [JSOI2007]麻将
  4. Hadoop HDFS (3) JAVA訪问HDFS之二 文件分布式读写策略
  5. Yet Another Multiple Problem 同余定理 bfs
  6. CachedIntrospectionResults 初始化
  7. css样式引入方式,及常用设置标签样式
  8. 你是多大年龄感觉自己开窍了,明白许多人世间的道理?
  9. 2021年你想转行吗?写给迷茫的你!
  10. 复制一个空洞文件且忽略掉其空洞内容
  11. 超炫的3D特效程序管理功能android
  12. Jeecg框架中的一些常用属性(query,dictionary,funname,formatterjs,replace)
  13. PX4 代码中 position_estimator_inav(互补滤波)理解
  14. Android 取消壁纸,android – 壁纸设置强制关闭
  15. word中的英文字体选择
  16. java wms erp自动化立体仓库管理系统 进出库 源码 源代码 程序
  17. nagios的nsca被动模式及自动添加nsca服务
  18. OpenSearch 学习
  19. 元宇宙技术在职业教育示范性虚拟仿真实训基地建设项目上的前景展望
  20. 青龙面板+xdd-plusQQ机器人便捷登陆查询保姆级搭建教程

热门文章

  1. java下载整个文件夹_Java下载目录中的所有文件和文件夹
  2. IT30: 统一标准新PC安装套路!
  3. sql统计总数及不同状态总数
  4. 阿里云免费SSL证书申请及收费版说明
  5. 人与人之间的信任 无信不交往,守信方长久
  6. word表格中自动插入行编号
  7. 酒店计算机操作规程,某酒店前台操作规程..doc
  8. 认真对待生活中的每一件事情
  9. 2016 大学老友小聚
  10. java 多线程 发邮件_Spring多线程批量发送邮件(ThreadPoolTaskExecutor)