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

人工智能29

查看我的版本:

Module: tf.compat | TensorFlow Core v2.6.0 Compatibility 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 Core no 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 ;

Original: https://blog.csdn.net/lililinglingling/article/details/121613694
Author: lililinglingling
Title: no model named “compat“ ,Tensorflow 版本问题

相关文章
查看外网IP 人工智能

查看外网IP

404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com Original: https://ww...
Python 中的 PIL 库 人工智能

Python 中的 PIL 库

一、 简介 Pillow 是 Python 中较为基础的图像处理库,主要用于图像的基本处理,比如裁剪图像、调整图像大小和图像颜色处理等。与 Pillow 相比,OpenCV 和 Scikit-imag...