no model named “compat“ ,Tensorflow 版本问题

查看我的版本:

Module: tf.compat  |  TensorFlow Core v2.6.0Compatibility functions.no model named “compat“ ,Tensorflow 版本问题https://tensorflow.google.cn/versions/r2.6/api_docs/python/tf/compat?hl=en结果是我没从中找到解决方案(我看的不够仔细);no model named “compat“ ,Tensorflow 版本问题

tf1.0  到 tf2.0 的区别以及相关说明(并没解决我的问题,但可能对你有用,这里也贴出来):TensorFlow 1.x vs TensorFlow 2 – Behaviors and APIs  |  TensorFlow Coreno model named “compat“ ,Tensorflow 版本问题https://tensorflow.google.cn/guide/migrate/tf1_vs_tf2

  同样这里不想降低版本,因此尝试通过以下方法解决:

# import tensorflow as tf
import tensorflow.compat.v1 as tf

到这里,就报如题描述的错误啦;

此时我尝试通过直接使用 tf2 的模块及函数直接替换掉 tf1 相关的模块函数,但显然相当麻烦,要去查找每个模块可能对应的新的模块函数,就在这个过程中,我找到了下面这位博主的解决方案:

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

当然,在后文与Tensorflow1.0 相关的调用时,要进行相应的修改:

# 动态申请显存

# config = tf.ConfigProto()
# config.gpu_options.allow_growth = True
# self.sess = tf.Session(config=config)

config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True 
self.sess = tf.compat.v1.Session(config=config)

非常感谢这位博主,参考链接:tensorflow2.0版本中Session模块_yuan_xiangjun的博客-CSDN博客注:安装好Tensorflow2.0后,当使用Session时,报错AtributeError: module ‘tensorflow’ has no attribute ‘Session’:错误的意思是tensorflow模块没有Session属性,后来查阅资料发现,tensorflow2.0版本中的确没有Session这个属性解决问题如下:`import tensorflow as tf…no model named “compat“ ,Tensorflow 版本问题https://blog.csdn.net/yuan_xiangjun/article/details/105469721

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年3月28日
下一篇 2023年3月28日

相关推荐