首页 > 技术文章 > AttributeError: module ‘tensorflow‘ has no attribute ‘InteractiveSession‘或 ‘placeholder‘的解决

ay2021 2021-02-17 09:39 原文

问题提示:

AttributeError: module ‘tensorflow’ has no attribute ‘InteractiveSession’
或者:
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

解决:

如果安装的是高版本的tf(tf2.x),跑比较旧的代码容易出现这种报错。解决方案:注释tf的引用,换为兼容模式。

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

 

替换掉 import tensorflow as tf 即可。

虽然提示 no module named compat ,仍然运行成功了。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

 

推荐阅读