查看我的版本:
Module: tf.compat | TensorFlow Core v2.6.0 Compatibility functions.https://tensorflow.google.cn/versions/r2.6/api_docs/python/tf/compat?hl=en ;结果是我没从中找到解决方案(我看的不够仔细);
tf1.0 到 tf2.0 的区别以及相关说明(并没解决我的问题,但可能对你有用,这里也贴出来):TensorFlow 1.x vs TensorFlow 2 – Behaviors and APIs | TensorFlow Core 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)
Original: https://blog.csdn.net/lililinglingling/article/details/121613694
Author: lililinglingling
Title: no model named “compat“ ,Tensorflow 版本问题
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/718652/
转载文章受原作者版权保护。转载请注明原作者出处!